getRecordCreateDefaults

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

getRecordCreateDefaults uses this User Interface API resource.

  • objectApiName—(Required) A supported object.

  • formFactor—The layout display size for the record. An array containing any of these values:

    • Large—(Default) Use this value to get a layout for desktop display size.
    • Medium—Use this value to get a layout for tablet display size.
    • Small—Use this value to get a layout for phone display size.

To get a value to pass as the formFactor, use the @salesforce/client/formFactor module.

  • recordTypeId—The ID of the record type (RecordType object) for the new record. If not provided, the default record type is used.
  • optionalFields—An optional array of field names. If an optional field is accessible to the context user, it’s included in the response. If it isn’t accessible to the context user, it isn’t included in the response, but it doesn’t cause an error. 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.
  • dataRecord Defaults

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

  • errorFetchResponse

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.

See Also