force:recordData

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

A force:recordData component defines the parameters for accessing, modifying, or creating a record using Lightning Data Service.

<aura:component>
    <force:recordData aura:id="forceRecordCmp"
        recordId="{!v.recordId}"
        layoutType="{!v.layout}"
        fields="{!v.fieldsToQuery}"
        mode="VIEW"
        targetRecord="{!v.record}"
        targetFields="{!v.simpleRecord}"
        targetError="{!v.error}" />
</aura:component>
Methods

This component supports the following methods.

  • getNewRecord: Loads a record template and sets it to the targetRecord attribute, including predefined values for the object and record type.
  • reloadRecord: Performs the same load function as on init using the current configuration values (recordId, layoutType, mode, and others). Doesn’t force a server trip unless required.
  • saveRecord: Saves the record.
  • deleteRecord: Deletes the record.

Attributes

Attribute Name Attribute Type Description Required?
body Component[] The body of the component. In markup, this is everything in the body of the tag.
fields String[] Specifies which of the record's fields to query.
layoutType String Name of the layout to query, which determines the fields included. Valid values are FULL or COMPACT. The layoutType and/or fields attribute must be specified.
mode String The mode in which to load the record: VIEW (default) or EDIT.
recordId String The record Id
targetError String Will be set to the localized error message if the record can't be provided.
targetFields Object A simplified view of the fields in targetRecord, to reference record fields in component markup.
targetRecord Object The provided record. This attribute will contain only the fields relevant to the requested layoutType and/or fields atributes.

Events

Event Name Event Type Description
recordUpdated COMPONENT Event fired when the record has changed.