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

Displaying records of an indirectly related object on detail page of other object

I have say ,3 objects A, B & C.

B has MasterDetail relationship with object C and Lookup relationship with object A

Now on detail page of object A  record I want to display corresponding records from object C

How could this be done using VF and apex?



Try the below code snippet as reference


====VF Page======


<apex:page standardController="objA__c" extensions="DeatilsForObjC" >
<apex:pageBlock >

<apex:pageBlockTable value="{!recrds}" var="u">
<apex:column headerValue="ObjectC Name" value="{!u.objC__r.Name}"/>
<apex:column headerValue="ObjectC ID" value="{!}"/>



========Apex Controller========


public class DeatilsForObjC {

public List<objB__c> recrds{get;set;}
public objA__c ob{get;set;}

public DeatilsForObjC(ApexPages.StandardController controller)
ob = new objA__c();
recrds=new List<objB__c>();
recrds=[select objC__r.Name, from objB__c where];




After creating this page, add this VF page in the page layout of object A.


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 


I modified your example as follows:



Customer Group (ObjectA) -> Account (ObjectB) -> Contact (ObjectC)


public class DetailsForContacts {

public List<Account> recrds{get;set;}
public Customer_Group__c ob{get;set;}

public DeatilsForContact(ApexPages.StandardController controller)
ob = new Customer_Group__c();
recrds=new List<Account>();
recrds=[select Contact__r.Name, from Account where];




on save i get the following error:

Error: Compile Error: Didn't understand relationship 'Contact__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 12 column 8