- By using Lightning Data Service you can easily make lightning components that deal with a single record and embed that component to the detail page of that record.
- You can even make reusable lightning components that deal with similar data so that they can be reused at multiple record detail pages.
- One big advantage of Lightning Data Service is that you don't have to make any apex controller.
- Suppose you have two components that work on the same data - one is updating the record and other is displaying the record so as you update the record, the component that is displaying the record is updated automatically and you don't have to take care of any event handling in this case as you normally do in Lightning Components.
- There are some considerations also that we have to take care while using LDS one of which is that you can only query a single record and that too by Id of that record only while using LDS.
During my session, I made multiple lightning components, each for one operation in CRUD. Out of which I gave the demo of read, update and delete operation only but I have the whole code for each operation including create. So let's discuss about each component first and then I'll handover the code to you.
- Read (LDSComp) - This component displayed the name of the contact.
- Edit (LDSCompEdit) - This component allows you to edit the contact's first name and last name.
- Delete (LDSCompDelete) - This component allows you to delete the contact.
- Create (LDSCompNew) - This component allows you to create a new lead.
So let's jump on to the code. You can download the whole code of this LDS demo from here.
If you want to see whole code step by step, you can clone the github repo on your system and then move step by step as I have created 4 different branches in which in each branch one extra component is added to the wrapper component.
You can switch between all 4 branches in the following order:-
- read
- update
- delete
- create
If you want to learn how to setup MavensMate you can refer to my other blog post How to setup MavensMate with your favorite text editor for Salesforce.
So, make sure you have tried all the crud operations of LDS by using the code given in the repo. If you have any doubts or problems you can comment below or contact me directly on my twitter handle which is - @rahulcoder
This comment has been removed by a blog administrator.
ReplyDeleteI am really tired of saying this again and again now. Please don't spam
Delete