{"id":3158,"date":"2020-06-13T01:00:03","date_gmt":"2020-06-13T06:30:03","guid":{"rendered":"https:\/\/emizentech.com\/blog\/?p=3158"},"modified":"2025-01-02T11:58:50","modified_gmt":"2025-01-02T11:58:50","slug":"lightning-data-service-in-lwc","status":"publish","type":"post","link":"https:\/\/emizentech.com\/blog\/lightning-data-service-in-lwc.html","title":{"rendered":"How To Use Lightning Data Service In LWC In Salesforce"},"content":{"rendered":"\r\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/sites\/2\/2020\/06\/component-apex-controller.jpg\" alt=\"component apex controller\" class=\"wp-image-3161\" \/><\/figure><\/div>\r\n\r\n\r\n\r\n<p>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.<br><br>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\u2019t 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.<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/sites\/2\/2020\/06\/component-lightning-data-service.jpg\" alt=\"component lightning data service\" class=\"wp-image-3162\" \/><\/figure><\/div>\r\n\r\n\r\n\r\n<p>So here comes LDS for rescue.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">How Beneficial<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\"><li>No need to write Apex Code or SOQL query<\/li><li>Support most standard and all custom object<\/li><li>Reduce server load, database load, and network transfer by fetching data once.<\/li><li>Share cache data across components<\/li><li>Support field level security and sharing rules so no need to worry about data security and visibility<\/li><li>Support CRUD operations<\/li><li>Supports offline in Salesforce1<\/li><li>Can use in aura as well as LWC<\/li><\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Limitations<\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\"><li>Not all object supports LDS Check for supported standard object <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.lightning.meta\/lightning\/data_service_considerations.htm\" target=\"_blank\" rel=\"noopener\">Lightning Aura Components Developer Guide<\/a><\/li><li>Can not use for Vf pages<\/li><li>No bulk support.<\/li><\/ul>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/emizentech.com\/contact-us.html?utm_source=blog&amp;utm_medium=banner&amp;utm_campaign=emizen_blog\"><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/sites\/2\/2020\/05\/hire-salesforce-developers-1.png\" alt=\"hire salesforce developers\" class=\"wp-image-2389\" \/><\/a><\/figure><\/div>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">How To Use In LWC?<\/h2>\r\n\r\n\r\n\r\n<p>You can use it in LWC by importing UI API.<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code><code class=\"d-block\">'lightning\/uiRecordApi'<\/code><\/code><\/pre>\r\n\r\n\r\n\r\n<p>After importing this you can use wire adapters and functions.<\/p>\r\n\r\n\r\n\r\n<p>Also, you can use components like<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code><code class=\"d-block\">lightning-record-edit-form, lightning-record-form, and lightning-record-view-form<\/code><\/code><\/pre>\r\n\r\n\r\n\r\n<p>You can also call your custom APEX controller as<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code><code class=\"d-block\">@salesforce\/apex\/methodName<\/code><\/code><\/pre>\r\n\r\n\r\n\r\n<p>I hope this blog will give a basic understanding of LDS. In the next blog, we will learn record fetching by UI API.<\/p>\r\n\r\n\r\n\r\n<p>Also, if you ever need <a href=\"https:\/\/emizentech.com\/salesforce.html\">salesforce development services<\/a> then look no further because Emizentech has a great team of expert <a href=\"https:\/\/emizentech.com\/salesforce-consulting.html\">salesforce consultants and developers<\/a>.<\/p>\r\n\r\n\r\n\r\n<h4 class=\"wp-block-heading\">Also Read: <a href=\"https:\/\/emizentech.com\/blog\/dynamic-css-in-lightning-web-component.html\">How To Use Dynamic Styling In LWC In Salesforce<\/a> and <a href=\"https:\/\/emizentech.com\/blog\/call-apex-method-in-lightning-web-components.html\">How To Call Apex Method In Lightning Web Components<\/a><\/h4>\r\n","protected":false},"excerpt":{"rendered":"<p>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<\/p>\n","protected":false},"author":39,"featured_media":3241,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[87],"tags":[],"class_list":{"0":"post-3158","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-salesforce-development"},"jetpack_featured_media_url":"https:\/\/emizentech.com\/blog\/wp-content\/uploads\/sites\/2\/2020\/06\/How-To-Use-Lightning-Data-Service-In-LWC-In-Salesforce-1.jpg","featured_image_src":"https:\/\/emizentech.com\/blog\/wp-content\/uploads\/sites\/2\/2020\/06\/How-To-Use-Lightning-Data-Service-In-LWC-In-Salesforce-1.jpg","featured_image_src_square":"https:\/\/emizentech.com\/blog\/wp-content\/uploads\/sites\/2\/2020\/06\/How-To-Use-Lightning-Data-Service-In-LWC-In-Salesforce-1.jpg","author_info":{"display_name":"Virendra Sharma","author_link":"https:\/\/emizentech.com\/blog\/author\/salesforce"},"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/posts\/3158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/comments?post=3158"}],"version-history":[{"count":1,"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/posts\/3158\/revisions"}],"predecessor-version":[{"id":44719,"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/posts\/3158\/revisions\/44719"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/media\/3241"}],"wp:attachment":[{"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/media?parent=3158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/categories?post=3158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emizentech.com\/blog\/wp-json\/wp\/v2\/tags?post=3158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}