Activity › Forums › Salesforce® Discussions › What is Lightning Data Services in Salesforce?
Tagged: Apex Code, Data Services, Field Level Security, FLS, Lightning Data Service, Salesforce Apex Controller, Salesforce Lightning, Server-Side Controller
-
What is Lightning Data Services in Salesforce?
Posted by madhulika shah on July 26, 2018 at 11:29 amWhat is Lightning Data Services in Salesforce?
William replied 6 years, 1 month ago 6 Members · 5 Replies -
5 Replies
-
Lightning Data Service is used to load, create, edit, or delete a record in your component without requiring Apex code. It handles sharing rules and field-level security for you. In addition to not needing Apex, it improves performance and user interface consistency. Lightning Data Service identifies and eliminates requests that involve the same record data, sending a single shared data request that updates all relevant components. Not only does this eliminate inconsistent data between components, it also provides a way to cache data to work offline in case the user gets disconnected, intelligently syncing the data once the connection is restored. Data access with Lightning Data Service is simpler than the equivalent using a server-side Apex controller.
-
Hi,
Use Lightning Data Service to load, create, edit, or delete a record in your component without requiring Apex code. Lightning Data Service handles sharing rules and field-level security for you. In addition to not needing Apex, Lightning Data Service improves performance and user interface consistency.
At the simplest level, you can think of Lightning Data Service as the Lightning Components version of the Visualforce standard controller. While this statement is an over-simplification, it serves to illustrate a point. Whenever possible, use Lightning Data Service to read and modify Salesforce data in your components.Data access with Lightning Data Service is simpler than the equivalent using a server-side Apex controller. Read-only access can be entirely declarative in your component’s markup. For code that modifies data, your component’s JavaScript controller is roughly the same amount of code, and you eliminate the Apex entirely. All your data access code is consolidated into your component, which significantly reduces complexity.
Lightning Data Service provides other benefits aside from the code. It’s built on highly efficient local storage that’s shared across all components that use it. Records loaded in Lightning Data Service are cached and shared across components. Components accessing the same record see significant performance improvements, because a record is loaded only once, no matter how many components are using it. Shared records also improve user interface consistency. When one component updates a record, the other components using it are notified, and in most cases, refresh automatically.
Loading a Record
Loading a record is the simplest operation in Lightning Data Service. You can accomplish it entirely in markup.
Saving a Record
To save a record using Lightning Data Service, call saveRecord on the force:recordData component, and pass in a callback function to be invoked after the save operation completes.
Creating a Record
To create a record using Lightning Data Service, declare force:recordData without assigning a recordId. Next, load a record template by calling the getNewRecord function on force:recordData. Finally, apply values to the new record, and save the record by calling the saveRecord function on force:recordData.
Deleting a Record
To delete a record using Lightning Data Service, call deleteRecord on the force:recordData component, and pass in a callback function to be invoked after the delete operation completes.
Record Changes
To perform tasks beyond rerendering the record when the record changes, handle the recordUpdated event. You can handle record loaded, updated, and deleted changes, applying different actions to each change type.
Errors
To act when an error occurs, handle the recordUpdated event and handle the case where the changeType is “ERROR”.
Considerations
Lightning Data Service is powerful and simple to use. However, it’s not a complete replacement for writing your own data access code. Here are some considerations to keep in mind when using it.
Lightning Data Service Example
Here’s a longer, more detailed example of using Lightning Data Service to create a Quick Contact action panel.
SaveRecordResult
Represents the result of a Lightning Data Service operation that makes a persistent change to record data.Hope this helps!
-
Hi
Salesforce introduced Lightning Data Service in Winter 17 as a pilot program. Use Lightning Data Service to load, create, edit, or delete a record in your component without requiring Apex code. Lightning Data Service handles sharing rules and field-level security for you.
It’s built on highly efficient local storage that’s shared across all components that use it. Records loaded in Lightning Data Service are cached and shared across components. Components accessing the same record see significant performance improvements, because a record is loaded only once, no matter how many components are using it. Shared records also improve user interface consistency. When one component updates a record, the other components using it are notified, and in most cases, refresh automatically.
Advantages of Lightning Data Service
No need to write any Apex class
No need to write SOQL
Field level security and record sharing is inbuilt
CRUD operation supported
Shared cache is used by all standard and custom components
Auto notification to all components
Supports offline in Salesforce 1THanks.
-
hi,
Use Lightning Data Service to load, create, edit, or delete a record in your component without requiring Apex code.At the simplest level, you can think of Lightning Data Service as the Lightning Components version of the Visualforce standard controller.It’s built on highly efficient local storage that’s shared across all components that use it. Records loaded in Lightning Data Service are cached and shared across components. Components accessing the same record see significant performance improvements, because a record is loaded only once, no matter how many components are using it.
thanks.
-
Lightning Data Services (LDS) is a new mechanism in Salesforce that was proposed in winter 2017 to edit, delete, or update records in Lightning Components. LDS reduces the need for APEX methods and improves the overall performance and user-interface consistency. With the help of simple mark-ups, records and the related fields can be quickly loaded to the Lightning Component. In this way, LDS could be taken as a strong consideration before you start with next component development. This can be definitely be taken as the big deal for the future projects.
Log In to reply.
Popular Salesforce Blogs

Protect your Data in Salesforce | All You Need to Know
Salesforce is a powerful cloud-based customer relationship management (CRM) system that helps you manage your customers, leads, accounts, and more. It can also be a…

Salesforce LinkedIn Integration - Complete Guide
Salesforce is a global web-based company known for its customer relationship management (CRM) product. It also acts as a Software-as-a-Service (SaaS) provider and Platform-as-a-service (PaaS) provider…

What is Salesforce AppExchange?
AppExchange is the first-rate choice for the enterprise app market. App exchange applications customized for salesforce and every IT company. It has proved that it…