getRecordCreateDefaults

Use this wire adapter to get default information and data needed to create a record.

Syntax 

1import { getRecordCreateDefaults } from 'lightning/uiRecordApi';
2@wire(getRecordCreateDefaults, { objectApiName: string })
3propertyOrFunction;

User Interface API Resource 

1GET /ui-api/record-defaults/create/{objectApiName}

getRecordCreateDefaults uses this User Interface API resource.

Parameters 

Parameter NameTypeDescriptionRequired?
objectApiNameStringA supported object.Yes
formFactorString[]The layout display size for the record. An array containing any of these values:
  • Large—(Default) Layout for desktop display size.
  • Medium—Layout for tablet display size.
  • Small—Layout for phone display size.
  • To get a value to pass as the formFactor, use the @salesforce/client/formFactor module.
recordTypeIdStringThe ID of the record type (RecordType object) for the new record. If not provided, the default record type is used.
optionalFieldsString[]An optional array of field names. If an optional field is accessible to the context user, it’s included in the response. Specify names in the format ['ObjectApiName.FieldName'].

Read the data that’s returned by the wire adapter using a property or function.

propertyOrFunction—A private property or function that receives the stream of data from the wire service.

  • If a property is decorated with @wire, the results are returned to the property’s data property or error property.
  • If a function is decorated with @wire, the results are returned in an object with a data property and an error property.

Returns 

  • dataRecord Defaults

    In the response, don’t use the recordTypeInfo property. Instead, use the recordTypeId property, which is returned for every record.

  • errorFetchResponse

Usage 

To create UI that lets a user create a record, first get information about which fields are required. This adapter’s response contains the default field values for a new record of the object type specified in {apiName}. It also contains object metadata and the corresponding layout for Create mode. In the Salesforce user interface, an admin with “Customize Application” permission can mark a field as required in a layout. When you’re building UI, to determine which fields to mark as required in a layout for create and update, use the ObjectInfo.fields[fieldName].required property.

The ldsGenerateRecordInputForCreate component in the lwc-recipes repo shows an example on how to use getRecordCreateDefaults.

Tip

See Also

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.