0

I have an lwc component with 2 picklist fields from contact object. Below is the html and Js code snippets of the same:

HTML:

<lightning-combobox
   data-id="cntype" 
   class="slds-m-bottom_small" 
   name="Functional Role" 
   label="Primary Functional Role" 
   value={value} 
   placeholder="-Select-" 
   options={pickListvaluesByRecordType} 
   onchange={onValueSelection}
></lightning-combobox>

<lightning-combobox
    data-id="cntype"
    class="slds-m-bottom_small"
    name="Business Role"
    label="Business Role"
    value={value}
    placeholder="-Select-"
    options={businessrole}
    onchange={onValueSelection}
></lightning-combobox>

JS:

import {
  getPicklistValuesByRecordType,
  getbusinessrole
} from "lightning/uiObjectInfoApi";
import ccRecordID from '@salesforce/label/c.ContactRecordId';
import CONTACT_OBJECT from "@salesforce/schema/Contact";
export default class MyComponent extends LightningElement {
    @track businessrole;
    @track pickListvaluesByRecordType;
    @track contactType;

    /*picklist value 1 */
    @wire(getPicklistValuesByRecordType, {
        recordTypeId: ccRecordID,
        objectApiName: CONTACT_OBJECT
    })
    wiredRecordtypeValues({ data, error }) {
        if (data) {
            this.pickListvaluesByRecordType = data.picklistFieldValues.Functional_Role__c.values;
        } else if (error) {
            console.log(error);
        }
    }

    /* picklist value 2 */
    @wire(getbusinessrole, {
        recordTypeId: ccRecordID,
        objectApiName: CONTACT_OBJECT
    })
    wiredBusinessRoleValues({ data, error }) {
        if (data) {
            this.businessrole = data.picklistFieldValues.Business_Role__c.values;
        } else if (error) {
            console.log(error);
        }
    }

    /* OnvalueSelection Function */
    onValueSelection(event) {
        this.contactType = event.target.value;
        this.businessrole = event.target.value;
    }
}

Now, this one is working fine only when there is one wire decorator. If I update the JS with the above 2 decorators, the page itself is not rendering. There is no error but the page is not getting displayed.

Can anyone please let me know on how to get lwc working with 2 wire decorators included.

Thanks!

9
  • can you share your full js code ?
    – Badbaxx
    Jan 20, 2021 at 8:23
  • @Badbaxx, Rest all has normal import statement and handlesave methods. These are responsible for picklist fields in the page and when I include second wire method, page is not working. If i remove that, page is working fine.
    – SFDCUser
    Jan 20, 2021 at 8:32
  • I ask that because It could be interesting to see how you deal with onValueSelection fuction.
    – Badbaxx
    Jan 20, 2021 at 8:50
  • @Badbaxx, I have updated above js with onvalueSelection function.
    – SFDCUser
    Jan 20, 2021 at 9:05

1 Answer 1

0
@wire(getbusinessrole, {

Should probably be:

@wire(getPicklistValuesByRecordType, {

I can't see any other reason you'd get a failure.

P.S. When you include code on this site, make sure you show your import statements, too. This helps us confirm the data type(s) for the imported symbols.

2
  • sfdcfox, can we use same @wire methods for different picklist fields as one is holding Functional_Role__c field and another is holding Business_Role__c field?
    – SFDCUser
    Jan 20, 2021 at 12:09
  • @SFDCUser Certainly, although I don't see why you have two wire methods in this case, because all the data is available in one call.
    – sfdcfox
    Jan 20, 2021 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .