I am new to LWC, i have few RecordTypes for the Service object, i am trying to insert the record with the record type (Mobile Service Record Type), but with the below code record is getting created with the default RecordType only..


    <lightning-record-edit-form object-api-name={serviceObject} onsuccess={handleServiceCreated}>
        <lightning-input-field field-name={namefield}
        <lightning-button type="submit" variant="brand" label="Create Account"></lightning-button>


import { LightningElement, api, wire, track } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import SERVICE_OBJECT from '@salesforce/schema/Service__c';
import SERVICE_NAME from '@salesforce/schema/Service__c.Name';

export default class RecordTypeTest extends LightningElement {
    @api recordId;
    @api objectApiName;
    @api serviceObject = SERVICE_OBJECT;

    @track objectInfo;
    @track namefield = SERVICE_NAME;

    fields = [SERVICE_NAME];

    @wire(getObjectInfo, { objectApiName: SERVICE_OBJECT })

    get recordTypeId() {
        const rtis = this.objectInfo.data.recordTypeInfos;
        return Object.keys(rtis).find(rti => rtis[rti].name === 'Mobile Service Record Type');


Is this the complete code of your LWC? If it is you are not using the recordTypeId you got from wire adapter in the lightning-record-edit-form using record-type-id attribute. Please refer to the documentation about record-edit-form.

If this is not the complete code, please share your full to understand the problem better.

Note: I am only writing my comments/suggestions as an Answer as I don't have enough reputation to comment on the question.

  • Hi Naga, i have added the record-type-id={recordTypeId} in the cmp, it is working fine, thanks
    – Chowdary
    Mar 12 '20 at 6:32

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.