Lightning Data Service (Beta)

Lightning Data Service is now in beta. Use Lightning Data Service to load, create, edit, or delete a record in your component, without using Apex code. Lightning Data Service handles sharing rules and field-level security for you. Lightning Data Service also improves performance and user-interface consistency.

With the move to beta, force:recordPreview has been deprecated and replaced with force:recordData. If you’re using force:recordPreview, you must refactor your components to use force:recordData.

With force:recordData, the targetRecord attribute has been updated to return records in a new shape using the User Interface API. See User Interface API Developer Guide: Response Bodies: Record. The following example shows how lookups have changed.

Old shape:
{
    "Lookup__c": "001xx000003DORBAA4",
    "Lookup__r.Id": null,
    "Lookup__r.Name": null,
    "Lookup__r": {
        "Id": "001xx000003DORBAA4",
        "Name": "Test",
        "sobjectType": "Account"
    }
}
New shape:
{
    "fields": {
        "Lookup__c": {
            "displayValue": "001xx000003DORBAA4",
            "value": "001xx000003DORBAA4"
        },
        "Lookup__r": {
            "displayValue": "Test",
            "value": {
                "apiName": "Account",
                "fields": {
                    "Id": {
                        "displayValue": "001xx000003DORBAA4",
                        "value": "001xx000003DORBAA4"
                    },
                    "Name": {
                        "displayValue": "Test",
                        "value": "Test"
                    }
                },
                "id": "001xx000003DORBAA4",
                "recordTypeInfo": null
            }
        }
    }
}

force:recordData includes a new attribute called targetFields, which is populated with a simplified view of the record’s fields. targetFields is automatically updated whenever Lightning Data Service detects a record change. v.targetFields.Name is equivalent to v.targetRecord.fields.Name.value. A simple way to update force:recordPreview usage to force:recordData is to change references from targetRecord to targetFields.

The following example shows the targetFields attribute within the force:recordData 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}" />