function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Larry Caper II 7Larry Caper II 7 

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!
Prateek Singh SengarPrateek Singh Sengar
Hi Larry,
Your scenario can be achieved by creating an inline visualforce page. Since this inline page will be create for Case page layout the VF page will use Case standard controller and an custom extension to support your requirement.

Please see below few articles that can guide you through the process.
http://salesforcesource.blogspot.com/2008/10/how-to-create-custom-related-list-on.html
http://blog.jeffdouglas.com/2009/05/08/inline-visualforce-pages-with-standard-page-layouts/

 
Larry Caper II 7Larry Caper II 7
PrateekSinghSengar,
The Listing lookup field lives on the Case Record. I want to show all Booking Rules related to that Listing record as a section on the Case page layout. Basically, there will be a section, on the Case page layout, of all Booking Rules related to the Listing within the Case. I'm not sure where to start to get the mapping correct or build a controller or VF page. 
 
Prateek Singh SengarPrateek Singh Sengar
Hi Larry,
Since i am not aware of the structure field api names of your org its hard to provide the exact code. However i have tried to create an skeleton code that should help you in building up the rest. Please see below the skeleton code. Items in BOLD needs your org specific inputs.

Once you have created the below extension and vf page, go to your Case layout and add this vf page.

Create an extension class
public class BookingRuleRelatedListExt{
    private List<BOOKING_RULE_OBJECT_NAME> brList;
    private Case case;
    private caseId;
    public sampleDetailPageCon(ApexPages.StandardController controller) {
        this.case= (Case)controller.getRecord();
        caseId = case.Id;
    }
    public List<BOOKING_RULE_OBJECT_NAME> getBookingRule()
    {
        //Query List id
       String ListingRecId = '';
       case  = [Select Id, LISTING_LOOKUP__ID from case where id =: caseId ];
       ListingRecId = case.LISTING_LOOKUP__ID;

       brList = [Select Id,Name from BOOKING_RULE_OBJECT_NAME where LIST_MASTER_DETAIL =: ListingRecId];
      return brList;
    }
}

Create a vf page "BookingRuleRelatedList"
<apex:page standardController="Case" extensions="BookingRuleRelatedListExt">
<apex:form >
 <apex:pageblock id="CustomList" title="Related Booking Rule"  >
   <apex:pageBlockTable value="{!BookingRule}" var="bRec">
        <apex:column value="{!bRec.Name}"/>
        <apex:column value="{!bRec.ID}"/>
    </apex:pageBlockTable>
   </apex:pageblock>
</apex:form>
</apex:page>
Larry Caper II 7Larry Caper II 7
Thank you for the skeleton, however I am receiving the following error: "Error: Compile Error: unexpected token: '<' at line 2 column 17". I included the API Names within the code, as well as below:
  • Booking Rule: BookingRule__c
  • Listing: Listing__c
  • Case: Case  
public class BookingRuleRelatedListExt{
    private List< <b> BookingRule__c </b> > brList;
    private Case case;
    private caseId;
    public sampleDetailPageCon(ApexPages.StandardController controller) {
        this.case= (Case)controller.getRecord();
        caseId = case.Id;
    }
    public List<BookingRule__c> getBookingRule()
    {
        //Query List id
       String ListingRecId = '';
       case  = [Select Id, <b>Listing__r</b>from case where id =: caseId ];
       ListingRecId = case.<b>Listing__r</b>;

       brList = [Select Id,Name from <b>BookingRule__c </b>where <b>Listing__c </b>=: ListingRecId];
      return brList;
    }
}
Prateek Singh SengarPrateek Singh Sengar
Hi Larry,
Those <b> </b> tags were added automatically by the forum when i tried to apply BOLD to them. Please remove them from your code.
Larry Caper II 7Larry Caper II 7
PrateekSinghSengar,
I removed them from the code. However, I receive the following error after trying to save: "
Error: Compile Error: Identifier name is reserved: case at line 3 column 18". I
Prateek Singh SengarPrateek Singh Sengar
Please try
 
public class BookingRuleRelatedListExt{
    private List<BookingRule__c> brList;
    private Case caseRec;
    private caseId;
    public sampleDetailPageCon(ApexPages.StandardController controller) {
        this.caseRec= (Case)controller.getRecord();
        caseId = caseRec.Id;
    }

    public List<BookingRule__c> getBookingRule()
    {
        //Query List id
       String ListingRecId = '';
       caseRec = [Select Id, Listing__c from case where id =: caseId ];
       ListingRecId = caseRec.Listing__c;

       brList = [Select Id,Name from BookingRule__c where Listing__c =: ListingRecId];
      return brList;
    }
}

 
Larry Caper II 7Larry Caper II 7
PrateekSinghSengar, 
I received the following error: "Error: Compile Error: unexpected token: ';' at line 4 column 18"
Prateek Singh SengarPrateek Singh Sengar
public class BookingRuleRelatedListExt{
    private List<BookingRule__c> brList;
    private Case caseRec;
    private String caseId;
    public sampleDetailPageCon(ApexPages.StandardController controller) {
        this.caseRec= (Case)controller.getRecord();
        caseId = caseRec.Id;
    }

    public List<BookingRule__c> getBookingRule()
    {
        //Query List id
       String ListingRecId = '';
       caseRec = [Select Id, Listing__c from case where id =: caseId ];
       ListingRecId = caseRec.Listing__c;

       brList = [Select Id,Name from BookingRule__c where Listing__c =: ListingRecId];
      return brList;
    }
}

 
Prateek Singh SengarPrateek Singh Sengar
Hi Larry,
I dont have the schema in my org to try out the code, the code is just skeleton so that you can update it based on your org structure. Like the error suggested the constructor name was invalid. Now constructor name should be same as class name therefore chanding the constructor name to match class name should fix the issue
 
public class BookingRuleRelatedListExt{
    private List<BookingRule__c> brList;
    private Case caseRec;
    private String caseId;
    public BookingRuleRelatedListExt(ApexPages.StandardController controller) {
        this.caseRec= (Case)controller.getRecord();
        caseId = caseRec.Id;
    }

    public List<BookingRule__c> getBookingRule()
    {
        //Query List id
       String ListingRecId = '';
       caseRec = [Select Id, Listing__c from case where id =: caseId ];
       ListingRecId = caseRec.Listing__c;

       brList = [Select Id,Name from BookingRule__c where Listing__c =: ListingRecId];
      return brList;
    }
}