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.
-
recordId
—(Required) The ID of a record from a supported object. -
fields
—(Eitherfields
orlayoutTypes
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 theoptionalFields
parameter.Specify field names in the format
ObjectApiName.FieldName
orObjectApiName.JunctionIdListName
.Polymorphic fields aren't supported. Including a polymorphic field in
fields
can result in an invalid field error. -
layoutTypes
—(Either{fields}
orlayoutTypes
is required) Specifies the fields to return. If this property is specified, the response is a union oflayoutTypes
,modes
, andoptionalFields
.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 adescribeLayout()
call. In this case, we recommend usingoptionalFields
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.
-
modes
—Optional iflayoutTypes
is specified. IflayoutTypes
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.
-
optionalFields
—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 formatObjectApiName.FieldName
orObjectApiName.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’sdata
property orerror
property. - If a function is decorated with
@wire
, the results are returned in an object with adata
property and anerror
property.
-
data
—RecordIn the Record response, don’t use the
recordTypeInfo
property. Instead, use therecordTypeId
property, which is returned for every record. -
error
—FetchResponse
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
- Understand the Wire Service
- Handle Errors in Lightning Data Service
- Salesforce Objects Supported by lightning/ui*Api Modules
- Get Record Data
- createRecord(recordInput)
- updateRecord(recordInput, clientOptions)
- deleteRecord(recordId)