function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vincent Bastos 7Vincent Bastos 7 

How to load record type id for lightning-record-edit-form?

I'm trying to set the record-type-id of a lightning-record-edit-form in a Lightning Web Component. However, every time I add the code for the record type id, the page is blank. This is to create a new record, not edit one.

Controller:
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import MY_OBJECT from '@salesforce/schema/myObject__c';

export default class myClass extends LightningElement {

    @api recordTypeId;
    @api objectInfo;

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

    get recordTypeId() {
        console.log('get recordtypeid');
        // Returns a map of record type Ids 
        const rtis = this.objectInfo.data.recordTypeInfos;
        return Object.keys(rtis).find(rti => rtis[rti].name === 'record type 1');
    }
}
Component:
<lightning-record-edit-form 
                object-api-name={myObject}
                record-type-id={recordTypeId}
                onsubmit={handleSubmit}
                onsuccess={handleSuccess}
                onerror={handleError}>
</lightning-record-edit-form>