
With more than 8,000 votes over the past seven years, the ability to filter a related list is a missing feature that has plagued admins time and time again. I’m sure you’ve been told you can create a filtered related list on a standard page layout via custom Visualforce page using a standard set controller and extension. Yes, that is a bit of a mouthful. While that is true, there are various obstacles to doing it this way, not limited to:
- Page placement is restricted above all other related lists in a standard page layout
- You lose the standard bookmark link at the top of the detail page
- The look and feel is just not the same
- Having the Visualforce/Javascript/jQuery knowledge to hackily make it look like a normal related list
There is actually a much more simple way to do it and still get every bit of the functionality of a standard related list. For example, if you want to only show active assets on the standard account page layout, follow these steps:
- Add a lookup to Account on the Asset called ‘Active Account’
- Within your before update /before insert trigger on Asset ie if(trigger.isBefore && (trigger.isUpdate || trigger.isInsert))
- Have some simply code set the lookup just created to the asset accountid if it’s active or null if not
</p> <pre>// apex for (Asset a : trigger.new) { if (a.Status == 'Active') { a.Active_Account__c = a.AccountId; } else { a.Active_Account__c = null; } } </pre> <p>
Optionally, you can parameterize the trigger using custom settings so that your admin can configure the related lists declaratively if the acceptable values of status were to change, for example.