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
Nagarjuna Reddy NandireddyNagarjuna Reddy Nandireddy 

How to show three different object records in vfpage?

Hi all,

i have three objects i.e ob1,ob2,ob3.
in this three objetcs having relation is:
ob1(parent)----> ob2(child)----> ob3(grand child).
here i want show related records in one table i.e in visualforce page.
please help me for this.

Regards,
Nagarjuna Reddy Nanireddy

     
 
sfdcMonkey.comsfdcMonkey.com
hi Nagarjuna
You can handle this easily with a wrapper class. Example code:
public myController


{
    public List<wrapper> wrapperList {get; set;}
    public myController
    {
        List<A__c> aList = [Select Id, name From A__c];
        List<B__c> bList = [Select Id, name From B__c];
        List<C__c> cList = [Select Id, name From C__c];

        for(A__c a : aList)
        {
            wrapper w = new wrapper(a);
            wrapperList.add(a);
        }

        //Do the something for bList and cList;
    }

    public class wrapper
    {
        public A__c a;
        public B__c b;
        public C__c c;

        public wrapper(A__c a)
        {
            this.a = a;
        }

        public wrapper(B__c b)
        {
            this.b = b;
        }

        public wrapper(C__c c)
        {
            this.c = c;
        }

    }
}
Page
<apex:dataTable value="{!wrapperList}" var="wrapper" >
    <apex:column>
        <apex:facet>A name</apex:facet>
        {!wrapper.a.name}
    </apex:column>
    <apex:column>
        <apex:facet>B name</apex:facet>
        {!wrapper.b.name}
    </apex:column>
    <apex:column>
        <apex:facet>C name</apex:facet>
        {!wrapper.c.name}
    </apex:column>
</apex:dataTable>

Thanks
Mark it best answer if it helps you :)
 
Arunkumar KathiravanArunkumar Kathiravan
Hi Nagarjuna,
Please try below codes. A__c(parent) ----> B__c(child) ----> C__c​(grand child)

Controller
 
{
    public List<C__c> cList {get; set;}
    public myController
    {
        cList = [Select Id, name, B__r.Name, B__r.A__r.Name From C__c];
    }

}

Page
 
<apex:dataTable value="{!cList}" var="val" >
    <apex:column>
        <apex:facet>A name</apex:facet>
        {!cList.B__r.A__r.name}
    </apex:column>
    <apex:column>
        <apex:facet>B name</apex:facet>
        {!cList.B__r.name}
    </apex:column>
    <apex:column>
        <apex:facet>C name</apex:facet>
        {!cList.name}
    </apex:column>
</apex:dataTable>

Thanks,
Arunkumar