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
bhanu reddy 24bhanu reddy 24 

how to show 3 objects data in data table by using visualforce page

how to show 3 objects data in data table by using visualforce page
Pradeep SinghPradeep Singh
Are the objects related to each other. If Yes, how.?
bhanu reddy 24bhanu reddy 24
how to show 3 objects data in data table by using soql query in visualforce page
Pradeep SinghPradeep Singh
If you don't have any relationship(master-detail/Lookup) then you can't query it in a single query.
If you have then it depends how the objects are related to each other.

Case 1 :- 1 Parent and 2 Childs Objects
List<ParentObject__c> parentObjList = [Select id,name, (select id,name from ChildObj__r),(select id,name from ChildObj2__r) from ParentObject__c] ;

Case 2 :- Grand Parent > Parent > Child

List<ParentObj__c> parentObjList = [Select id,name,grandParent__c,grandParent__r.name,(select id,name from Child__r) from ParentObj__c];

Case 3 :- 2 Parents and 1 Child Objects

List<ChildObj__c> childObjList = [select id,name,parent1__c,parent1__r.name,parent2__c,parent2__r.name from ChildObj__c];
 
bhanu reddy 24bhanu reddy 24
thank you for responding me
Pradeep SinghPradeep Singh
Hi, there should be a space between checkbox__c and from.
Also use relationship names while using inner queries.
bhanu reddy 24bhanu reddy 24
thank you for responding
 
Pradeep SinghPradeep Singh
<apex:page controller="accContrl">
    <apex:pageBlock>
        <apex:pageBlockTable value="{!accList}" var="acc">
            <apex:column value="{!acc.id}"/>
            <apex:column value="{!acc.name}"/>
            <apex:column headerValue="Contact">
                <apex:pageBlockTable value="{!acc.Contacts}" var="con">
                    <apex:column value="{!con.name}"/>
                </apex:pageBlockTable>
            </apex:column>
            <apex:column headerValue="Opportunity">
                <apex:pageBlockTable value="{!acc.Opportunities}" var="opp">
                    <apex:column value="{!opp.name}"/>
                </apex:pageBlockTable>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>


public class accContrl{
    
    public List<Account> accList {get;set;}
    public accContrl(){
        accList =[Select id,name,(select id,name from contacts),(select id,name from opportunities) from account];
    }
}
If this solves your query, please mark it as solved.