You need to sign in to do that
Don't have an account?
Vincent 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:
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>