Newer Version Available

This content describes an older version of this product. View Latest

Lightning Data Service Example

Here’s a longer, more detailed example of using Lightning Data Service to create a Quick Contact action panel.

Example

This example is intended to be added as a Lightning action on the account object. Clicking the action’s button on the account layout opens a panel to create a new contact.Example of Lighning action using Lightning Data Services

This example is similar to the example provided in Configure Components for Record-Specific Actions. Compare the two examples to better understand the differences between using @AuraEnabled Apex controllers and using Lightning Data Service.

ldsQuickContact.cmp
ldsQuickContactController.js

The callback passed to getNewRecord() must be wrapped in $A.getCallback() to ensure correct access context when the callback is invoked. If the callback is passed in without being wrapped in $A.getCallback(), any attempt to access private attributes of your component results in access check failures.

Even if you’re not accessing private attributes, it’s a best practice to always wrap the callback function for getNewRecord() in $A.getCallback(). Never mix (contexts), never worry.

Note

ldsQuickContactHelper.js