Jun 26, 2017

Sujesh Ramachandran

Update, Delete Record from DataTable in Lightning



In Lightning, let's see how we can easily access the current record in a list view or data table to update/delete. Those who are familiar with Visualforce will see a slight change in the concept to achieve this as we have a follow a component based design to update/delete record in a list view or data table.

In the below example, we are fetching account records and displaying in a data table with Update, Delete Icon for each record. User could click on any account specific edit, delete to fire the respective action. In this code snippet, we are just showing the trick to access the respective record Id and record object of the user selected account, so that the user could use the selected record id, record object to either edit or delete the record.

Now lets see the parent component(Demo_CRUD_Component) wherein we are fetching accounts and displaying the list of records using an Iteration. In iteration we use a child component(Demo_CRUD_Component_ROW) to display each record. To child component, we are passing single record, so that the edit, delete event can be easily handled in the child component. Let's see the code of parent component(Demo_CRUD_Component), related controller and apex class.


Here is the code of child component wherein we are handling the edit and delete for each record. Since we have designed the child component for each record, it is easy to get the current record or object, selected by user for either edit, delete. Let's see the code of child component(Demo_CRUD_Component_ROW).



Here is the the screenshot associated with the example:



follow me @ramsujesh

Sujesh Ramachandran

About Sujesh Ramachandran -

Co-Founder @ Fingertipplus Technologies | Co-Organizer of Coimbatore Salesforce Developer Group | Full Stack Coder | Blogger

Subscribe to this Blog via Email :

4 comments

Write comments
Mona
AUTHOR
June 21, 2018 5:57 AM delete

Can you please share your code

Reply
avatar
ABHISHEK
AUTHOR
December 27, 2020 11:38 AM delete

I tried similar in LWC but all the data is coming in single Data but on placing similar code on parent showing data in correct cells

Reply
avatar
Unknown
AUTHOR
January 07, 2021 11:26 PM delete

Edit button and delete is not working

Reply
avatar
Unknown
AUTHOR
July 27, 2021 11:29 PM delete

Edit button and delete is not working
can you please help for resolve same

Reply
avatar