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 Name | Type | Description | Required? |
---|---|---|---|
recordId | String | The ID of a record from a supported object. | |
fields | String[] | 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 . fields can result in an invalid field error. | See description |
layoutTypes | String[] | 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 .
describeLayout() call. In this case, we recommend using optionalFields to specify a default set of fields. | See description |
modes | String[] | 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.
| |
optionalFields | String[] | 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’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)