0

I am encountering the following error in Salesforce Lightning page wherein I try to render some fields based on values of multi-select picklist field:

enter image description here

I even tried includes but same error occurs. Would really appreciate any help or suggestions about this one.

Meanwhile, following are the current codes I have:

contactLWC.html

<template>
    <div class="slds-theme_default">  
        <lightning-record-edit-form object-api-name="Contact" record-id={recordId} onsuccess={handleSuccess}>
            <lightning-messages></lightning-messages>
                <div> 
                    <lightning-input-field field-name="MultiSelectPicklist__c"
                        onchange={handleMultiSelectPicklistChange}>
                    </lightning-input-field>  
                </div>
                <div if:true={renderField1}>    
                    <lightning-input-field field-name="Field1__c">
                    </lightning-input-field>          
                </div> 
                <div if:true={renderField2}>    
                    <lightning-input-field field-name="Field2__c">
                    </lightning-input-field>          
                </div>     
        </lightning-record-edit-form>
    </div>
</template>

contactLWC.js

import { LightningElement, track, api, wire } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import MULTIPICKLIST_FIELD from '@salesforce/schema/Contact.MultiSelectPicklist__c';

const fields = [MULTIPICKLIST_FIELD];

export default class EditFSCalculationToolLWC extends NavigationMixin(LightningElement) {
    @api recordId;
    @track renderField1;
    @track renderField2;

    @wire(getRecord, { recordId: '$recordId', fields })
    contact;

    get renderField1() {
        return getFieldValue(this.contact.data.includes('ValueA'), MULTIPICKLIST_FIELD) ? true : false; 
    }

    get renderField2() {
        return getFieldValue(this.contact.data.includes('ValueB'), MULTIPICKLIST_FIELD) ? true : false; 
    }

    handleMultiSelectPicklistChange(event) {
        this.contact.MultiSelectPicklist__c = event.detail.value;
    }
    
    handleSuccess( event ) { 
        //some code....
 
    }

}
1

You are trying to access data from contact. Yoi are getting the error because of the way you are trying to access the data.

The contact.data is null by default as the value is not yet provisioned by wire service. In addition to that, the correct way to access data inside the getter would be.

return this.contact.data &&  getFieldValue(this.contact.data,MULTISELECT_PICKLIST).includes('ValueB');
1
  • I modified the condition statement and followed yours, it works now! Thanks for your help :)) – Ertyq Oct 20 '20 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.