Enquiry Now
component apex controller

In this blog, we will learn about lightning data service and use in LWC. Basically every web component needs server call to show data. Now if we are taking the traditional approach suppose we have 3 components in a page and all are showing data about Account.

Now we can see in a single page for the same data there is three apex call and the database will be accessed three times. If data changes by component 1 it will reflect new data while others will have no information about this so they will keep showing the old date. Definitely you don’t want this. So after knowing all this issue we will be happy if we can get a middle man who can fetch data from Salesforce, cached it at his end, and send the data to all components. Also if it can notify all components for any change in data.

component lightning data service

So here comes LDS for rescue.

How Beneficial

  • No need to write Apex Code or SOQL query
  • Support most standard and all custom object
  • Reduce server load, database load, and network transfer by fetching data once.
  • Share cache data across components
  • Support field level security and sharing rules so no need to worry about data security and visibility
  • Support CRUD operations
  • Supports offline in Salesforce1
  • Can use in aura as well as LWC

Limitations

hire salesforce developers

How To Use In LWC?

You can use it in LWC by importing UI API.

'lightning/uiRecordApi'

After importing this you can use wire adapters and functions.

Also, you can use components like

lightning-record-edit-form, lightning-record-form, and lightning-record-view-form

You can also call your custom APEX controller as

@salesforce/apex/methodName

I hope this blog will give a basic understanding of LDS. In the next blog, we will learn record fetching by UI API.

Also, if you ever need salesforce development services then look no further because Emizentech has a great team of expert salesforce consultants and developers.

Also Read: How To Use Dynamic Styling In LWC In Salesforce and How To Call Apex Method In Lightning Web Components

Get in Touch

Avatar photo
Author

With over a decade of experience in eCommerce development services and CRM solutions, Mr. Virendra has helped businesses worldwide leverage technology to build, optimize, and transform their IT infrastructure and applications. An avid researcher, Mr. Virendra is recognized by his peers as a tech evangelist with a strong passion for emerging technologies and their potential to solve real-world business challenges. Discover how Team Virendra can help your business embrace modern technology, simplify operations, and drive greater productivity. Connect.

whatsapp