Passing in allowOnSaveDuplicate or recordTypeId isn’t currently supported. To prevent the creation of duplicate records, use a duplicate rule with a matching rule.
Note
Returns
A Promise object that resolves with the created record. The record contains data for the fields in the record layout.
Usage
Before you use this wire adapter, make sure that there isn’t an easier way to create the data. Consider using the lightning-record-*-form components to work with records. To update a record, use updateRecord instead.
Use createRecord by passing in the record input. To create a RecordInput object, use generateRecordInputForCreate(record,objectInfo). Alternatively, pass in a recordInput object with the apiName and fields properties.
1import{createRecord}from "lightning/uiRecordApi";2import ACCOUNT_OBJECT from "@salesforce/schema/Account";3import NAME_FIELD from "@salesforce/schema/Account.Name";45export default class createRecordExample extends LightningElement{6 name;78 handleInput(event){9 this.name = event.target.value;10}1112 async handleCreate(){13 const fields = {};14 // Map the user input to the fields15 fields[NAME_FIELD.fieldApiName] = this.name;1617 // Configure your recordInput object with the object and field API names18 const recordInput = {apiName: ACCOUNT_OBJECT.objectApiName, fields};1920 try{21 // Invoke createRecord22 const account = await createRecord(recordInput);23}catch(error){24 // Handle error25}26}27}