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

Avatar photo
Author

With a decade of experience in eCommerce technologies and CRM solutions, Virendra has been assisting businesses across the globe to harness the capabilities of information technology by developing, maintaining, and improving clients’ IT infrastructure and applications. A leader in his own rights his teammates see him as an avid researcher and a tech evangelist. To know how the team Virendra can assist your business to adopt modern technologies to simplify business processes and enhance productivity. Let’s Talk.

whatsapp