Record Data

force:recordData

Provides the ability to create, read, update, and delete Salesforce records.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App

A force:recordData component defines the parameters for accessing, modifying, or creating a record using Lightning Data Service. You have granular control on how you want to display or render the data in your custom component.

We recommend that you use the simpler lightning:recordForm component for accessing, modifying, or creating a record if you don't need a custom layout or custom rendering of record data.

To load a record, specify its record ID, the component attributes, and a list of fields in your custom component. You can add your custom component to a record home page in the Lightning App Builder, or as a custom action.

In the following example, the record ID is supplied by the implicit recordId attribute added by the force:hasRecordId interface. A lightning:card component is used to display the record data via accountRecord on the targetFields attribute.

This component doesn't support all Salesforce standard objects. For example, the Event and Task objects are not supported.

For a list of supported objects, see the User Interface API Developer Guide.

force:recordData loads data asynchronously since it may retrieve data from the server. To track when the record is loaded or changed, use the recordUpdated event or place a change handler on targetRecords or targetFields.

recordUpdated

The event fired when the record is loaded, updated, or deleted.

To see changed field values in a handler for the recordUpdated event, ensure that any field in the fields attribute is also in the page layout. Otherwise, the field changes aren't available in the handler.

The recordUpdated event returns the following parameters.

ParameterTypeDescription
changeTypestringThe type of change that fired the event, with values corresponding to "ERROR, "LOADED", "REMOVED", or "CHANGED".
changedFieldsobjectThe fields that are updated on the record when the changeType is "CHANGED".

For more information, see the Lightning Aura Components Developer Guide.