Salesforce has released the most awaited feature for Lightning Developers, Lightning Data Services – Standard Controller of Lightning Components! To speed up Lightning component development, Salesforce brought in Lightning Data Services. Lightning Data Service is a collection of lightning tags, methods, and events. We can relate it to Visualforce Standard Controller.
- 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.
- At the simplest level, you can think of Lightning Data Service as the Lightning Components version of the Visualforce standard controller. Whenever possible, use Lightning Data Service to read and modify Salesforce data in your components.
- 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.
Lightning Data Services consist of following:
- force:recordPreview tag
- getNewRecord() method
- saveRecord() method
- deleteRecord() method
- recordUpdated Event
- changeType event parameter to check record update status
Let’s see what are the benefits of Lightning Data Services:
Lightning Data Service provides reusable Aura components that:
- Fetch records once, reducing network transfers, app server load, and database server load
- Cache record data on the client, separate from component metadata
- Share record data across components
- Enable progressive record loading, caching, and merging more fields and layouts into the cache
- Enable proactive cache population
- Promote consistency by using only one instance of the record data across multiple components
- Create notifications when record data changes
- Lightning components does not enforce Field Level security while displaying data fetched from Apex controller, unlike Visualforce pages. So, it was required to check CRUD permission in apex controller. This can be skipped if you use Lightning Data Services.
- If there are many components on record detail page, then for each component there was SOQL to fetch data which affects the performance of the entire page. But if we use LDS it’s performance will improve as time lag to fetch data from server side will be saved.
- Also, prebuilt Lightning controller methods like Save(), getNewRecord() will help to perform DML in Lightning itself with writing any Apex.
- Data consistency – As the record values stored on client side in the cache, it will remain same across all the components. If you update value of any field in one component, it will be consistent on another component and it notify & refresh other components automatically.
If you have a Lightning application that creates, reads, updates or deletes records, LDS is the best, most efficient way to do CRUD operations.
LDS is here to simplify developer life. Adopting LDS means you no longer have to write your own controller code. All of your data access code is contained within the LDS component, significantly reducing the complexity of your apps and pages. This reduced complexity means that you don’t have to spend as much time on performance and quality testing.
Lightning Data Service Example
- Lightning Data Service – Standard Controller for Lightning Components
- Use Lightning Data Service – No To Apex Controller In Lightning Components
- Lightning Data Service Basics
Keep your eyes on an upcoming blog entry for more real-time examples to develop the Lightning Components using Lightning Data Service.
Wait and Watch, more to come…