# `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

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

## Parameters

| Parameter Name | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                 | Required?                                                                         |
| -------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `record`       | Object | A [Record](https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_responses_record.htm#ui_api_responses_record) object that contains source data. To get data to build the Record object, use the [getRecord](/docs/platform/lwc/guide/reference-wire-adapters-record.md) wire adapters.                                                                                                                                 | ![Yes](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/checkmark.png) |
| `objectInfo`   | Object | The [ObjectInfo](https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_responses_object_info.htm#ui_api_responses_object_info) corresponding to the `apiName` on the record. To get the object info, use the [getObjectInfo](/docs/platform/lwc/guide/reference-wire-adapters-object-info.md) wire adapter. If provided, only fields with the property `updateable=true` (excluding `Id`) are included in the response. |                                                                                   |

## Returns

A [Record Input](https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_requests_record_input.htm) 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.

```javascript
import { LightningElement, api, wire } from "lwc";
import { getRecord, generateRecordInputForUpdate } from "lightning/uiRecordApi";
import { getObjectInfo } from "lightning/uiObjectInfoApi";

export default class WireGenerateRecordInput extends LightningElement {
  @api recordId;
  @api objectApiName;

  @wire(getRecord, {
    recordId: "$recordId",
    layoutTypes: "Full",
    modes: "Edit",
  })
  wiredRecord;

  get recordInputForUpdate() {
    if (!this.wiredRecord.data || !this.objectInfo.data) {
      return undefined;
    }

    const recordInput = generateRecordInputForUpdate(this.wiredRecord.data, this.objectInfo.data);
    return recordInput;
  }

  get errors() {
    return this.wiredRecord.error;
  }
}
```

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.

```javascript
{
  "fields":{
    "AccountId":"0011a0000000000AAA",
    "AssistantName":null,
    "AssistantPhone":null,
    "Birthdate":"1941-09-26",
    "Department":"Finance",
    "Description":null,
    "Email":"ajames@example.com",
    "Fax":"+1 415 1234567",
    "FirstName":"Ashley",
    "HomePhone":null,
    "LastName":"James",
    "LeadSource":"Public Relations",
    "MailingCity":"San Francisco",
    "MailingCountry":"USA",
    // More fields here
    "Id":"0031a0000000000AAA"
  }
}
```

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](https://github.com/trailheadapps/lwc-recipes/tree/main/force-app/main/default/lwc/ldsGenerateRecordInputForCreate) example in the lwc-recipes repository.
