0

I have a requirement where I have to add multiple related list of same object base on the some filter criteria in Salesforce Lightning.

For exm: Contact Roles is child object of Contact, now I have to add 2 related list of contact roles in Contact page layout. 1st related list based on Role1 and 2nd related list based on the Role-2 value.

I know in lightning it is possible via "Related List - Single", but the problem is in Add filter I am not able filter out the criteria based on the Child object's field, only Current Object or Parent object's fields are available for filtering.

Can someone pls suggest if I am doing something wrong or any work around! highly appreciated.


I am thinking to achieve my requirement with the help of following:

  1. Create a custom lightning components
  2. Use the data table to create related list structure
  3. Create custom tab to place my custom lightning component into that
1

What you are experiencing with the component visibility feature, is the expected behavior. You can find more on the component visibility feature on its documentation but the below excerpt provides as what is available in the filter criteria.

On record pages, you can choose record fields or advanced fields, such as fields from related objects or from a global object like User

The Lighting Page corresponds to how a "record" will be displayed in LEX (Lightning Experience). That will mean that any component's visibility on the page will be guided based on the current record instead of any other child record.

Moreover, the component is a "Related List", where you will have more than one record, so logically you won't be able to set a filter based on that for the component to be visible. Because in that scenario you will not be able to determine which record from the list will be utilized in the filter criteria to determine the visibility of the component.

  • Thanks Jayant for your valuable answer! But still I think Salesforce should provide filter criteria based on the child's field, because let's assume in one Account page layout I have to show 2 related list of opportunity. one is for the oppty where the Stage field is Closed Won and one is for the oppty where the Stage Field is In Progress... like wise don't you think it's a good idea in lightning, sorry if I am thinking very hypothetical!! – Nshukla6 Sep 5 '18 at 16:07
  • You cannot have it that way. Related List can contain more than 1 record at any time. You won't be able to determine which record to use to be able to display the component. You can build two different components and just show records filtered based on your criteria, but even in that case your component cannot be set to be visible based on any child record criteria. – Jayant Das Sep 5 '18 at 16:26
1

There are several approaches to this challenge (filtered related lists). You can implement them at the UI level by writing your own Lightning components that filter and present child objects, but I like to separate the UI and the underlying data by using a solution like that described by Doug Ayers (Filter Related Lists Without Code).

In summary, what you do is establish one lookup field that associates child with parent, and then several more lookups between the same objects that correspond to each of the filtered views you want to establish. Each of those additional lookups gets populated (with the same value as the "real" underlying lookup field) if and only if the child record matches the filters for that specific filtered view.

The actual population can be done with Process Builder, or in a trigger if the criteria are too complex.

Once that data model is established and working, you can use the out-of-the-box Lightning related list component to display one of the filtered relationships, obviating the need to write any UI code and taking advantage of all new UI development Salesforce provides.

  • Thanks David! I also thought this approach, but only disadvantage I could see that you have to create so many lookup fields and as we have only 40 lookup fields limit. So if someone wants to filter out more related list he needs to create so many lookup fields! – Nshukla6 Sep 8 '18 at 19:55
  • You're right, but I might argue that if you have dozens of potential filters the fitting solution is probably not a filtered related list as such, but a more sophisticated custom browsing or search interface. – David Reed Sep 8 '18 at 20:46
0

If you want to control visibility of related list component then you can follow steps explained by Jayant by using salesforce standard component visibility feature.

But if you want to control even data of that related list. For example, if you want- 1. To show only closed opportunities..or open opportunities. 2. Show multiple related list with filtered data then you can read through below solution.

Use salesforce free app Enhanced Lightning Grid

  • You can have multiple related list as per your need.
  • You can have filter based on fields added in configuration.
  • Source code is available on Github (https://github.com/ForceDotComLabs/EnhancedLightningGrid). You can play around and add your custom code if needed.
  • This app having issue while showing currency field as column and does not support record type selection. I've worked on that as well. I can share you gist link if needed.
  • The link to the package is very helpful, but its more to sort data within the component and to be used as a replacement for a related list. OP's question is more around visibility of the component itself on a lightning page. – Jayant Das Sep 5 '18 at 15:53
  • Right...should I remove my answer? – Ayub Sep 5 '18 at 15:55
  • Not all answers can be same and in some cases accurate. So I will leave that for your judgement. But if you feel that this answer adds value for OP in a different way, I will recommend to edit it to specifically call that out. – Jayant Das Sep 5 '18 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.