Related List with Inline Edit | Lightning Component Salesforce

Hey Users,

Sometimes it is painful if you have to edit multiple child records and you have to open each record and update them. This component will make Related List with Inline Edit support. You can edit multiple rows and save them instantly. Also, if any error will occur, it will be visible instantly as Toast Message.

This component supports multiple salesforce datatypes and all necessary validations are already present. Pros and cons of the component are-

Pros:
  • Single Unit Component
  • Major Exceptions Already Handled.
  • Inline Edit based on field permission. If no permission, no Inline Edit.
  • Auto Scroll-bar if more than 5 Child Records are present.
  • Supports major SF datatypes like Text, Textarea, Picklist, Number, Percent, Currency, Date, Time, DateTime, Checkbox, etc.
Cons:
  • Lookup, Rich Text Area, Geo-Location are yet in view mode only.

Demo GIF:

related list with inline edit lightning salesforce gif

Also Check, Multi-Select Lookup Lightning Component

Related-List-Inline-Edit-Multiple-datatype-supported

Step-1: Create an Apex controller

Our apex controller will have all the necessary Validations. Apex class will fetch the child records and save the records. Here we are using a wrapper class to pass data to the lightning component. Go to Dev. console > File > New > Apex Class.

We need to create an Exception class first to throw the custom exception.

Create MyException.cls Apex class.

 

Create AdvancedRelatedListController.cls Apex class and paste the below code.

 

Step-2: Create the AdvancedRelatedList Lightning Component.

For creating a new Lightning Component, go to dev. console > File > New > Lightning Component.

Now open the AdvancedRelatedList.cmp file and paste the below code.

 

Now open the controller file AdvancedRelatedListController.js and paste the below code.

 

Open the helper file AdvancedRelatedListHelper.js and paste the below code.

 

Open the helper file AdvancedRelatedList.design and paste the below code.

 

Now finally paste the CSS in the AdvancedRelatedList.css file.

 

Step-3: Now we will add the component on the record page.

Our component is ready to use. Let’s put it on the Record Detail Page. Go to your record > Click on setting Gear on top > Edit Page.

On the Lightning App Builder in the Left Pane, find Advanced Related List and drop it on the record page. Now you need to set the Header, Object API name, Fields API Name List, Icon Name, and check the checkbox if you want the Inline Edit button.

You can check the list of available icons here LDS Icons.

Add Advanced Related List to Lightning Page

Hurray… All Set… Now Save and Activate the Page from the top and click on the back Icon. Your Related List component is visible now.

Advanced Related List with Inline Edit Lightning Salesforce

Also Check:

For any queries or suggestions/queries, comment below.

Cheers … Happy Coding … 🙂

Subscribe
Notify of
guest
19 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Hamish

Hi, I am getting a compile error when saving the apex class: Invalid type: MyException. Can you please provide some guidance on how to resolve this?

newbe

absolutely great and exactly what i need. however, i have no idea what the test class for the controller should look like. can you help here?

Hamish

Any chance you have the test class ready to go?

Mark

Any chance you’ve converted this to a Lightning Web Component?

Rocky

Thanks for sharing! Test class and eventually an LWC would be awesome! Looking forward to building this out and testing.

Andrew

This is awesome, Is it possible to show more than 5 rows and can you sort a column ?

Andrew

Many thanks for the quick answer !

Andrew

Hi Suyash, this is awesome, but I need a test class to deploy ? Do you have the code for it ?

Andrew

Ok great I really want to deploy soon

John Doe

Anyway to get this to work with AccountContactRelation object? Trying to display any related contact while being able to edit.

Thank you!