Error while creating Account {“status”:400,”body”:{“message”:”An error occurred while trying to update the record. Please try again.”,”statusCode”:400,”enhancedErrorType”:”RecordError”,”output”:{“errors”:[],”fieldErrors”:{“Name”:[{“constituentField”:”Name”,”duplicateRecordError”:null,”errorCode”:”REQUIRED_FIELD_MISSING”,”field”:”Name”,”fieldLabel”:”Account Name”,”message”:”Required fields are missing: [Name]”}]}}},”headers”:{}}
The above exception occurs when using createRecord from ‘lightning/uiRecordApi’ if the fields variable name is different. The variable name should be fields. Do not use any other name while calling createRecord from ‘lightning/uiRecordApi’.
Sample error code:
let accountFields = {};
accountFields[ ACCOUNT_NAME_FIELD.fieldApiName ] = this.accountName;
console.log( 'accountFields is', JSON.stringify( accountFields ) );
const recordAccountInput = { apiName: ACCOUNT_OBJECT.objectApiName, accountFields };
createRecord( recordAccountInput )
Correct Code is following:
let fields = {};
fields[ ACCOUNT_NAME_FIELD.fieldApiName ] = this.accountName;
console.log( 'fields is', JSON.stringify( fields ) );
const recordAccountInput = { apiName: ACCOUNT_OBJECT.objectApiName, fields };
createRecord( recordAccountInput )