I'm trying to retrieve recordTypeInfo, & create a map of RecordType name & RecordType Id, for a custom object using getObjectInfo adapter from lightning/uiObjectInfoApi API, based on this example (https://developer.salesforce.com/docs/component-library/documentation/lwc/reference_wire_adapters_object_info).
This component is added on Lightning Record Page.
I keep receiving [Cannot read property 'data' of undefined] error.
Below is my code:-
opptyapplicationlist.html
<template>
<lightning-textarea value={recTypeMap} label="RecordType"></lightning-textarea>
</template>
opptyapplicationlist.js
import {LightningElement, track, wire, api} from 'lwc';
import {getObjectInfo} from 'lightning/uiObjectInfoApi';
import APPLICATION_OBJECT from '@salesforce/schema/Application__c';
export default class OpptyApplicationList extends LightningElement {
@api recordId;
@track recTypeMap = this.getAppRecType();
@wire(getObjectInfo, {objectApiName: APPLICATION_OBJECT}) objectInfo;
getAppRecType() {
const rtis = this.objectInfo.data.recordTypeInfos;
return Object.keys(rtis).find(rti => rtis[rti].name === 'SBV MasterClass');
}
}
Is there something amiss in the example, or am I missing something very obvious.