This post is part of the #NoCodeNovember series. In this post I will show you how to use native related lists to separate and filter records with NO code and NO visualforce.

Have your users ever asked for a way to filter related lists or have multiple related lists that separate records based on criteria – much like how Open Activities and Activity History related lists separate Task records based on their status?

A common request I get is how to filter the Contacts related list on Account page, for example, to separate out “Active vs. Inactive” contacts. Or filter out HubSpot noisey activities from the real meetings and logged calls entered by the sales team. Or for customers who track forecasting opportunities along with actual orders in same Opportunity object but with different record types, how to show them in different related lists.

Sounds reasonable, right? Unfortunately, as of this writing, Salesforce currently does not natively support filtering related lists. There are two big ideas on the Idea Exchange requesting this very feature and are tentatively on the road map (safe harbor):

Workarounds exist but usually involve writing code or using a third-party app. One free workaround is Custom Related Lists by Kevin Poorman (@Codefriar). However, even then these solutions aren’t truly related lists as we know them but rather a fancy visualforce page you add to the page layout in a section among the other fields on the page layout. If you’re ok with using a solution that isn’t a native related list then that may be the way to go for you.

In the Visualforce approach, you’re limited to placing it among a field section on the page layout and can’t position it with the native related lists. So that’s a double whammy – had to write code and it doesn’t match the standard UI of related lists.

filteredcontacts_visualforce_on_pagelayout
Visualforce Page Added to Page Layout (not native)

Creating multiple related lists each using different filtering logic without any code or visualforce

Going back to our original example of trying to separate “Active vs. Inactive” Contacts, I’m going to show you how to setup multiple Contact related lists you can add to the Account page layout and each related list will filter the account’s contacts differently. This solution involves custom lookup fields and process builder.

Lookup Fields

This #NoCode solution for multiple related lists exploits the fact that every time you add a new lookup field on an object then the object the field references gets another related list showing those child records.

In our Contact example, let’s assume we have a custom checkbox called “Active” and that we want show on the Account page contacts separated out into two native related lists: one for Active contacts and one for Inactive contacts.

Using the lookup field trick, add two new lookup fields on the Contact object that both reference the Account object. You can name these whatever you want, perhaps “Active Lookup” and “Inactive Lookup”. You won’t ever show these fields on the Contact page layout, they are just behind-the-scenes fields to make the magic happen.

filteredcontacts_add_lookup_field_step1filteredcontacts_add_lookup_field_step2filteredcontacts_add_lookup_field_step3

Process Builder

Next we will automate using Process Builder the setting and clearing of these two new lookup fields. Whenever one of these lookup field’s value is set then on the Account page layout those contacts will appear in the related list associated with that lookup field. When the field is cleared then the contact record no longer will appear in that related list. And like magic we can now let our users intuitively toggle the “Active” checkbox on the contact page and the system will appropriately separate the contacts between the two related lists on the account page!

Our process will have two decision nodes, one checking if the contact “Active” checkbox is checked (true) and the other if it’s unchecked (false). When the checkbox is checked then we will have an immediate action update the contact record to do two things:

  1. Set the “Active Lookup” field with the value of the contact’s account ID
  2. Clear the “Inactive Lookup” field by setting it to value $GlobalConstant.null

As you can imagine, the same two actions occur for the other decision element but vice versa, we’ll set the “Inactive Lookup” and clear the “Active Lookup” fields.

filteredcontacts_processbuilder_step1filteredcontacts_processbuilder_step2filteredcontacts_processbuilder_step3

Activate the process then update some contacts to be active or inactive. Add the new related lists to your account page layout and voila! If you wanted, you could remove the standard “Contacts” related list and just keep the “Active” and “Inactive” related lists (to me that feels more like the “Open Activities” and “Activity History” experience of Task records that I was going for).

filteredcontacts_multiple_related_lists.png

Custom Buttons

The last step is to now create custom buttons for “New Contact” and “Merge Contacts” for your custom related lists. Check out slide 39 of my presentation for screen shots and instructions. The reason we need to do this is because one, the “New Contact” button on the custom related lists binds the account id name/value to the lookup field associated with that related list (either “Active Lookup” or “Inactive Lookup”) instead of the standard “Account Name” field, and two, because the “Merge Contacts” button isn’t automatically added to the custom related lists. Once you create those custom buttons and add them to the related lists on the page layout you’re golden!