In lwc-recipes, there is a component wireGetPicklistValues explaining how to fetch picklist values. This is the code below:
import { LightningElement, wire } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import TYPE_FIELD from '@salesforce/schema/Account.Type';
export default class WireGetPicklistValues extends LightningElement {
@wire(getPicklistValues, {
recordTypeId: '012000000000000AAA',
fieldApiName: TYPE_FIELD
})
picklistValues;
}
In the code above, recordTypeId value is hardcoded. I checked the documentation for getPicklistValues wire adapter. https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_wire_adapters_picklist_values
It's mentioned that to get recordTypeId, use the Object Info defaultRecordTypeId property, which is returned from getObjectInfo or getRecordUi.
So I modified my code as below, but it's still giving me runtime exception. Can anyone point me out where am I wrong?
import { LightningElement, wire, track } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import TYPE_FIELD from '@salesforce/schema/Account.Type';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
export default class WireGetPicklistValues extends LightningElement {
@wire(getPicklistValues, {
recordTypeId: this.objectInfo.data.defaultRecordTypeId,
fieldApiName: TYPE_FIELD
})
picklistValues;
@wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
objectInfo;
}