Posted in Lightning, Lightning Component

Lightning Data Service

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.

LDS Architecture

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

References :

  1. Lightning Data Service – Standard Controller for Lightning Components
  2. Use Lightning Data Service – No To Apex Controller In Lightning Components 
  3. Lightning Data Service Basics

What’s Next?

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…

pjimage.jpg

Advertisements

Author:

Hi! I am Pritam Shekhawat, Salesforce MVP. I am working as a 4x Certified Senior Salesforce developer as well I am a co-leader of Noida Salesforce user group. Most important thing which I like about Salesforce is giving back. There aren’t enough words in the dictionary to describe the significance of giving back.

One thought on “Lightning Data Service

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s