generateRecordInputForCreate(record, objectInfo)

Generates a representation of a record (Record Input) that can be used to create a record using createRecord(RecordInput). Passing in ObjectInfo filters the Record Input to only fields that are createable.

Syntax 

1import { generateRecordInputForCreate } from 'lightning/uiRecordApi';
2generateRecordInputForCreate(record: Record, objectInfo?: ObjectInfo): RecordInput

Parameters 

Here’s the table in markdown format:

Parameter NameTypeDescriptionRequired?
recordObjectA Record object that contains source data. To get data to build the Record object, use the getRecordCreateDefaults.Yes
objectInfoObjectThe ObjectInfo corresponding to the apiName on the record. If provided, only fields with the property createable=true (excluding Id) are included in the response.

Returns 

A Record Input object with its data populated from the given record. Returns all fields whose values are not nested records.

Usage 

Return the Record Input object on a contact record.

1import { LightningElement, api, wire } from "lwc";
2import { getRecordCreateDefaults, generateRecordInputForCreate } from "lightning/uiRecordApi";
3import CONTACT_OBJECT from "@salesforce/schema/Contact";
4
5export default class WireGenerateRecordInput extends LightningElement {
6  @wire(getRecordCreateDefaults, { objectApiName: CONTACT_OBJECT })
7  contactCreateDefaults;
8
9  get recordInputForCreate() {
10    if (!this.contactCreateDefaults.data) {
11      return undefined;
12    }
13
14    const contactObjectInfo =
15      this.contactCreateDefaults.data.objectInfos[CONTACT_OBJECT.objectApiName];
16    const recordDefaults = this.contactCreateDefaults.data.record;
17    const recordInput = generateRecordInputForCreate(recordDefaults, contactObjectInfo);
18    return recordInput;
19  }
20
21  get errors() {
22    return this.contactCreateDefaults.error;
23  }
24}

The object returned for a contact record by calling generateRecordInputForCreate with the value from getRecordCreateDefaults looks like this.

1{
2  "apiName": "Contact",
3  "fields": {
4    "AccountId": null,
5    "AssistantName": null,
6    "AssistantPhone": null,
7    "Birthdate": null,
8    "Department": null,
9    "Description": null,
10    "Email": null,
11    "Fax": null,
12    "FirstName": null,
13    "HomePhone": null,
14    "LastName": null,
15    // More fields here
16  }
17}

Release Preview

This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.