generateRecordInputForUpdate(record, objectInfo)

Generates a representation of a record (Record Input) that can be used to update a record using updateRecord(recordInput). Passing in ObjectInfo filters the Record Input to only fields that are updateable.

Syntax 

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

Parameters 

Parameter NameTypeDescriptionRequired?
recordObjectA Record object that contains source data. To get data to build the Record object, use the getRecord wire adapters.Yes
objectInfoObjectThe ObjectInfo corresponding to the apiName on the record. To get the object info, use the getObjectInfo wire adapter. If provided, only fields with the property updateable=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 record.

1import { LightningElement, api, wire } from "lwc";
2import { getRecord, generateRecordInputForUpdate } from "lightning/uiRecordApi";
3import { getObjectInfo } from "lightning/uiObjectInfoApi";
4
5export default class WireGenerateRecordInput extends LightningElement {
6  @api recordId;
7  @api objectApiName;
8
9  @wire(getRecord, {
10    recordId: "$recordId",
11    layoutTypes: "Full",
12    modes: "Edit",
13  })
14  wiredRecord;
15
16  get recordInputForUpdate() {
17    if (!this.wiredRecord.data || !this.objectInfo.data) {
18      return undefined;
19    }
20
21    const recordInput = generateRecordInputForUpdate(this.wiredRecord.data, this.objectInfo.data);
22    return recordInput;
23  }
24
25  get errors() {
26    return this.wiredRecord.error;
27  }
28}

The object returned by generateRecordInputForUpdate for a contact record looks like this. The fields returned depend on what your admin has included in the object’s layout.

1{
2  "fields":{
3    "AccountId":"0011a0000000000AAA",
4    "AssistantName":null,
5    "AssistantPhone":null,
6    "Birthdate":"1941-09-26",
7    "Department":"Finance",
8    "Description":null,
9    "Email":"ajames@example.com",
10    "Fax":"+1 415 1234567",
11    "FirstName":"Ashley",
12    "HomePhone":null,
13    "LastName":"James",
14    "LeadSource":"Public Relations",
15    "MailingCity":"San Francisco",
16    "MailingCountry":"USA",
17    // More fields here
18    "Id":"0031a0000000000AAA"
19  }
20}

We recommend using getRecord with layoutTypes (instead of fields) only if the resulting data will be used with the actual layout.

If you need specific fields, use fields or optionalFields rather than assume that those fields are present in the layout.

Example 

See the ldsGenerateRecordInputForCreate example in the lwc-recipes repository.