I'm trying to create record Type selection screen in LWC, but getting this error

afterRender threw an error in 'c:createContact' [Cannot read property 'recordTypeInfos' of undefined]


    <lightning-combobox name="recordType" label="Record Type" placeholder="Choose Status"



import { LightningElement, track, wire, api } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import CONTACT_OBJECT from '@salesforce/schema/Contact';

export default class CreateContact extends LightningElement {

    @track statusOptions;
    @track value;
    @api objectApiName;

    @track objectInfo;

    @wire(getObjectInfo, { objectApiName: CONTACT_OBJECT,})

    get recordTypeId() {
        // Returns a map of record type Ids 
        const rtis = this.objectInfo.data.recordTypeInfos;
        return rtis;

  • Use console.log(JSON.stringify(this.objectInfo)); to see what data you have. – Keith C May 19 '19 at 12:58

First thing i would do is put the combobox inside a div and only open it up once the wire data for recordtype comes from the object.

<div if:true={objectInfo.data}>
<lightning-combobox name="recordType" label="Record Type" placeholder="Choose Status"

Secondly in javascript where you are constructing the combobox for UI ,you need to match the format of lightning combobox specified in its documentation

 get recordTypeId1() {
      var recordtypeinfo = this.objectInfo.data.recordTypeInfos;
      var uiCombobox = [];
      console.log("recordtype" + recordtypeinfo);
      for(var eachRecordtype in  recordtypeinfo)//this is to match structure of lightning combo box
        uiCombobox.push({ label: recordtypeinfo[eachRecordtype].name, value: recordtypeinfo[eachRecordtype].name })
      console.log('uiCombobox' + JSON.stringify(uiCombobox));
    return uiCombobox;

Once the wire data comes back the combobox will openup in markup and your getter function will run

@wire(getObjectInfo, { objectApiName: CONTACT_OBJECT}) objectInfo;

Also the default value for the combo box UI, put a value which is in your object.

@track value = 'Client User';
  • Its working, but if I remove the if condition from the div then why I'm getting "afterRender threw an error in 'c:createContact' [Cannot read property 'recordTypeInfos' of undefined]" error? – salesforce Developer May 24 '19 at 10:17
  • 1
    @salesforceDeveloper - its a race condition, the wire data has not come back and you are trying to access objectInfo data through the getter expression function recordTypeId, thats why you need to open up the getter once the data comes back – RedDevil May 24 '19 at 16:30
  • Thanks for answer – salesforce Developer May 25 '19 at 18:03
  • 1
    Consider replacing the <div> with <template> to avoid influencing the rendered DOM structure – Kevin Venkiteswaran Jul 17 '19 at 15:28
  • FYI if you like concise syntax you can use Object.keys(recordtypeinfo).map(id => { value: id, label: recordtypeinfo[id].name }). The cautious might wish to .filter(id => { return recordtypeinfo[id].available }) before calling .map. – Adrian Larson May 21 '20 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.