According to the documentation here in order to retrieve a list of picklist values for an object we need to pass in a Record Type Id which can be retrieved using the getObjectInfo method.
The issue is that these are both wire functions and I cannot figure out how to chain these methods.
If I try code like the following:
getObjectInfo({ objectApiName: ACCOUNT_OBJECT })
.then(result => {
return getPicklistValues({recordTypeId: result.defaultRecordTypeId, fieldApiName: TYPE_FIELD});
})
.then(result => {
this.picklistValues = result.data
})
.catch(error => {
this.error = error;
});
I get an error
render threw an error in 'c:getpicklistexample' [Imperative use is not supported. Use @wire(getObjectInfo).]
If I try something like
@track rtId;
@wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
handleResult({error, data}) {
if(data) {
this.rtId = data.defaultRecordTypeId;
}
}
@wire(getPicklistValues, {recordTypeId: this.rtId,fieldApiName: TYPE_FIELD})
picklistValues;
Then it throws an internal server error. Anybody have an idea as to how I could retrieve the record type Id and then call to get the pick list values like the documentation suggests?
FYI my imports are:
import { LightningElement, wire, track } from 'lwc';
import { getPicklistValues, getObjectInfo } from 'lightning/uiObjectInfoApi';
import TYPE_FIELD from '@salesforce/schema/Account.Type';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';