getRecord

Use this wire adapter to get a record’s data.

The getRecord wire adapter uses this User Interface API resource, but doesn’t support all its parameters.

Parameter NameTypeDescriptionRequired?
recordIdStringThe ID of a record from a supported object.Yes
fieldsString[]Either fields or layoutTypes is required. A field or an array of fields to return. If the context user doesn’t have access to a field, an error is returned. If you’re not sure whether the context user has access to a field and you don’t want the request to fail if they don’t, use the optionalFields parameter. Specify field names in the format ObjectApiName.FieldName or ObjectApiName.JunctionIdListName. Polymorphic fields aren't supported. Including a polymorphic field in fields can result in an invalid field error.See description
layoutTypesString[]Either fields or layoutTypes is required. Specifies the fields to return. If this property is specified, the response is a union of layoutTypes, modes, and optionalFields.
  • Compact—Use this value to get a layout that contains a record’s key fields.
  • Full—Use this value to get a full layout.
Not all objects support layouts, for example, the Report object doesn’t include a describeLayout() call. In this case, we recommend using optionalFields to specify a default set of fields. To improve performance, specify fields instead of a layout whenever possible. Specify a layout only when you want the administrator, not the component, to control the fields that are provisioned. The component must handle receiving every field that is assigned to the layout for the context user.
See description
modesString[]Optional if layoutTypes is specified. If layoutTypes is not specified, this parameter is ignored. The access modes for the record. This value determines which fields to get from a layout. Layouts have different fields for create, edit, and view modes.
  • Create—Use this mode if you intend to build UI that lets a user create a record.
  • Edit—Use this mode if you intend to build UI that lets a user edit a record.
  • View—(Default) Use this mode if you intend to build UI that displays a record.
optionalFieldsString[]An optional field name or an array of optional field names. If a field is accessible to the context user, it’s included in the response. If a field isn’t accessible to the context user, it isn’t included in the response, but it doesn’t cause an error. Specify field names in the format ObjectApiName.FieldName or ObjectApiName.JunctionIdListName.

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

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

  • errorFetchResponse

To filter by criteria and work with dynamic record IDs easily, consider using the GraphQL wire adapter instead.

This example loads the record with required and optional fields. Use getRecord and getFieldValue to get a record and display its fields values. Replace the recordId value with your own.

Load the field values in a custom user interface.

This example loads the record by layout. Replace the recordId value with your own. Similar to the previous example, you can render field values using the getFieldValue wire adapter.

See Get Record Data for an example of using getRecord with a custom UI.

Use a Promise with then() and catch() blocks. To display errors, use toasts provided by the lightning/platformShowToastEvent module.

See Also