I'm trying to fetch the record values and show the label of the fields that have null values on the record detail page.
The code snippet is as below:
objectInfo = {};
@wire(getObjectInfo, {objectApiName: Lead_OBJECT })
LeadInfo({ data, error }) {
if (data) {
this.objectInfo = data;
}
}
@wire(getRecord, {
recordId: "$recordId",
fields: ['Company']
})
lead({error, data}) {
if (data) {
if (!data.fields['Company'].value) {
console.log(this.objectInfo.fields['Company'].label);//getting an error here
}
}
}
Error is objectInfo is undefined certain times and doesnt understand objectInfo.fields. This doesn't happen every time I load the page, only sometimes this error occurs on refresh. I understand this is because both run asynchronously. what is the way to make this work?