lightning/stateManagerRecord

This state manager gets record data.

Syntax 

Record retrieval requires a record ID, and a list of fields you want for the record.

1import { LightningElement } from 'lwc';
2import smRecord from "lightning/stateManagerRecord";
3
4export default class Example extends LightningElement {
5
6  const myRecord = smRecord({
7    recordId: string,
8    fields: string[],
9    optionalFields?: string[]
10  });
11}

Configuration Functions 

setConfig()

Provide the entire configuration as an object. This function is equivalent to the factory function when you create the state manager.

setRecordId()

Set the record ID of the record to retrieve.

setFields()

Set the record fields to retrieve. Provide field or an array of fields to return. Specify field names in the format ObjectApiName.FieldName, or use @salesforce/schema items.

If the context user doesn’t have access to a field, an error is returned. Use optionalFields if you’re not sure whether the context user has access to a field and you don’t want the state manager to return an error if they don’t.

setOptionalFields()

Set the record fields to retrieve. Provide field or an array of fields to return. Specify field names in the format ObjectApiName.FieldName, or use @salesforce/schema items.

Optional fields don't cause an error if the context user doesn’t have access to a field.

State Manager Properties 

status

The current status of the state manager. See status for details.

data

When status is "loaded", a Record.

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

error

When status is "error", this property contains details. See error for details.

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.