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

```javascript
import { generateRecordInputForCreate } from 'lightning/uiRecordApi';
generateRecordInputForCreate(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 `getRecordCreateDefaults`.                                                              | ![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. If provided, only fields with the property `createable=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 contact record.

```javascript
import { LightningElement, api, wire } from "lwc";
import { getRecordCreateDefaults, generateRecordInputForCreate } from "lightning/uiRecordApi";
import CONTACT_OBJECT from "@salesforce/schema/Contact";

export default class WireGenerateRecordInput extends LightningElement {
  @wire(getRecordCreateDefaults, { objectApiName: CONTACT_OBJECT })
  contactCreateDefaults;

  get recordInputForCreate() {
    if (!this.contactCreateDefaults.data) {
      return undefined;
    }

    const contactObjectInfo = this.contactCreateDefaults.data.objectInfos[
      CONTACT_OBJECT.objectApiName
    ];
    const recordDefaults = this.contactCreateDefaults.data.record;
    const recordInput = generateRecordInputForCreate(recordDefaults, contactObjectInfo);
    return recordInput;
  }

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

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

```javascript
{
  "apiName": "Contact",
  "fields": {
    "AccountId": null,
    "AssistantName": null,
    "AssistantPhone": null,
    "Birthdate": null,
    "Department": null,
    "Description": null,
    "Email": null,
    "Fax": null,
    "FirstName": null,
    "HomePhone": null,
    "LastName": null,
    // More fields here
  }
}
```
