Lightning Web Component: How to Get Picklist Values when recordTypeId is null
The issue is that $objectInfo.data.defaultRecordTypeId
never becomes non-undefined because this.objectInfo
is a function.
Try the code below instead.
Also remember that @wire
provisions a stream of values. If you wire to a function you need to "reset" all state in the if/else.
import { LightningElement, wire, track } from 'lwc';
import { getPicklistValues, getObjectInfo } from 'lightning/uiObjectInfoApi';
import SuppliesLeftUOM_Field from '@salesforce/schema/OpportunityLineItem.SuppliesLeftUOM__c';
import OpptyLiObject from '@salesforce/schema/OpportunityLineItem';
export default class aTemp extends LightningElement {
@track picklistValues;
// GET OBJECT INFO
@wire (getObjectInfo, {objectApiName: OpptyLiObject})
objectInfo;
// GET PICKLIST VALUES
@wire (getPicklistValues, {recordTypeId: '$objectInfo.data.defaultRecordTypeId', fieldApiName: SuppliesLeftUOM_Field})
wiredPicklistValues({ error, data }) {
// reset values to handle eg data provisioned then error provisioned
this.picklistValues = undefined;
if (data) {
this.picklistValues = data;
} else if (error) {
console.log(error);
}
}
}
To use getPicklistValues on OpportunityLineItem (and possibly other objects without record types) you can hard-code the master record type Id - 012000000000000AAA - like so:
@wire(
getPicklistValues,
{ recordTypeId: '012000000000000AAA', fieldApiName: PICKLIST_FIELD }
)
picklistValues;
This works for me in API 46.0. Hope this helps!