[SalesForce] Display Related List from Custom Object on Case Layout

I would like to display a related list from a custom object on my Case record. Please reference the information below:

  • Case Object: Contains a lookup field (Listing__c)
  • Listing Object: Master in a master-detail relationship with an object called Booking Rule(BookingRule__c)
  • Booking Rule Record: Due to the master-detial relationship, every Booking Rule record is associated to a Listing

Big Idea: The Case object and Booking Rule object are unrelated. However, they are somewhat related due to the Listing lookup field on the Case record. I would like to display the Booking Rules related list from my custom object (Listing__c) page layout on my Case page layout.

I hear a visualforce page will do the job. However, I'm unsure where to start, what APEX code to use and how to bring it all together.

Thanks in advance for anyone willing to help me out!

Best Answer

Use the <apex:relatedList> tag. It's dead simple.

<apex:page standardController="Case">
    <apex:relatedList subject="{!Cae.Listing__c}" list="BookingRules__r" />
</apex:page>

You can run this script to get the verbatim list name:

for (ChildRelationship relation : SObjectType.Listing__c.getChildRelationships())
    if (relation.getChildSObject() == BookingRule__c.sObjectType)
        system.debug(relation.getRelationshipName());