+ Start a Discussion
sfdc18sfdc18 

How to display child object field on visualforce page

Hi,

 

I have vf page with standard controller of obj1.

I want to display field of obj3 on that visualforce page.

 

Relation between these obj's are,

 

obj1--------Master

   |

   |

obj2--------Child of obj1 & Master of obj3

   |

   |

obj3--------Child of obj2

  

 

Kindly Help.

 

 

Avidev9Avidev9
You should understand first that child are always at the many side of the relationship. ! parent can have multiple childs.

So Obj1 can have multiple Obj2 records. And Each Obj2 can have multiple Obj3. Now the question changes to are you sure you want show fields? or the related records
sushant sussushant sus
through child to parent geting record is possible but parent to child is not possible
DaveHDaveH

It sounds like you just want to display a lookup correct?

 

You can reference lookups using the __r postfix on custom objects for this and display them with apex:outputField. 

 

For example:

public Object1__c obj1 {get; set;}

// In constructor
obj1 = [select Id, Object2__r.Object3__c from Object1__c where Id = 'XXX'];

 

 

You can display it with:

<apex:outputField value="{obj1.Object2__r.Object3__c"/>