代码之家  ›  专栏  ›  技术社区  ›  Tanmay Mahamulkar

如果人员帐户的姓氏为空,我如何在salesforce的lwc记录表上显示自定义错误消息?

  •  0
  • Tanmay Mahamulkar  · 技术社区  · 1 年前

    我想显示一条自定义错误消息,说明如果在使用记录表单创建的lwc组件上保持为空,请输入个人帐户的姓氏

    我期待一种显示自定义消息的方式。我的组件正在显示lwc验证,这是不正确的。我不想显示它,而是想显示一条自定义错误消息

     <template if:true={accountRecordId}>
            <div class="slds-p-right_large slds-p-bottom_large">
              <div class="slds-grid slds-gutters slds-m-top_medium">
                  <div class="slds-col slds-text-align_right">
              <lightning-button 
                variant="brand"
                label="View" 
                onclick={handleClickNavigate} 
                class="slds-m-top_medium_right"
              ></lightning-button>
              </div> 
              </div>
            </div>
            <div class="slds-p-around_x-small">
               <lightning-record-form
                columns="2"
                object-api-name={objectApiName}
                record-id={accountRecordId}
                fields={fieldsToDisplay}
                mode="view"     
              > 
          </lightning-record-form> 
        </div>
    
    I want to add a custom error message where if the account lastname is null show error for the person account type.
    
     @api recordId; //Case record ID 
        @track accountRecordId; //This will hold related account Id
        objectApiName = ACCOUNT_OBJECT;
        @track fields = [NAME_FIELD,BUSINESS_TYPE,BUSINESS_SUB_TYPE,SHIPPING_ADDRESS];
        @track fieldsToDisplay = []; //fields based on record type
        @track searchResults = [];
        customErrorMessage = '';
    
        //wire the case record to get the account id
        @wire(getRecord, { recordId: '$recordId', fields: [RELATED_ACCOUNT_ID_FIELD] })
        caseRecord({ error, data }) {
            if (data) {
                this.accountRecordId = getFieldValue(data, RELATED_ACCOUNT_ID_FIELD);
            } else if (error) {
                console.log(error);
            }
        }
    
        //get account details to determine business type
        @wire(getRecord, { recordId: '$accountRecordId', fields: [RECORD_TYPE_ID_FIELD] })
        accountRecord({ error, data }) {
            if (data) {
               // const recordTypeId = data.fields.RecordTypeId.value;
               const recordTypeId = getFieldValue(data, RECORD_TYPE_ID_FIELD);
    
                // Assume that you know the record type ID for person accounts
                const PERSON_ACCOUNT_RECORD_TYPE_ID = 'bshdfbjs'; // Replace with actual record type ID
    
                if (recordTypeId === PERSON_ACCOUNT_RECORD_TYPE_ID) {
                    this.fieldsToDisplay = [NAME_FIELD,BUSINESS_TYPE,PHONE_FIELD,BUSINESS_SUB_TYPE,,EMAIL_FIELD,SHIPPING_ADDRESS];
                } else {
                    this.fieldsToDisplay = this.fields;
                }
            } else if (error) {
                console.error('Error fetching account record type:', error);
            }
        }
    
    0 回复  |  直到 1 年前