Lightning data service with lwc

Telegram logo Join our Telegram Channel

Lightning Data Service (LDS) is an intermediate layer between Lightning Components (both LWC and Aura) and User Interface API of Salesforce, it runs on the browser. The records loaded in Lightning Data Service are cached on the browser and shared across all components on the page. If there are multiple components using the same record, the record is loaded once and shared with all components, this improves the platform performance as the record is not loaded multiple times.

What are the benefits of Lightning Data Service(LDS)?

  • Improved performance.
  • Caches data on the client-side, so server overhead is reduced.
  • Data is consistent between all components that are using LDS.
  • If data is changed at one place on the page, it will be refreshed in all other components on the page.
  • It does not cost against API usage calls.
  • Automatically refreshes the data in the cache when it is outdated.
  • It honors the CRUD permission for the records and objects.

How Lightning Data Service works?

When the data is loaded for the first time, LDS maintains that in the client-side cache. There is a specific lifetime for the data in the cache. Any request to data within that lifetime is served from cache.

For the request after cache data lifetime, LDS re-request the data and resets the lifetime. Meanwhile, if data changes, data is re-requested before its cache lifetime ends.

As Lightning Data Service is built on top of User Interface API, its respects the CRUD and field-level security and sharing settings. So the access of the data is controlled by users' specific accesses automatically.

How we can use Lightning Data Service in Lightning Web Components?

In lightning web components you can use LDS in two different ways

  • Standard Lightning web components lightning-record-edit-form, lightning-record-form, and lightning-record-view-form. -- Lightning record forms.
  • Lightning UI APIs, like uiRecordApi, uiObjectApi which contains wired adapters functions.

LWC Series

  1. Lightning Web Components Folder Structure
  2. Lightning data service with LWC

No comments :
Post a Comment

Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, email us at