+ Start a Discussion
rao venkyrao venky 


We have 3 objects Account, Contact, Opportunity.
   In a VF page, we need to display the names of contact & Opportunity which are related to Account.
Sachin KadianSachin Kadian
Hi, I am just pasting some rough code for this. 

Apex Class : 

public class testPageController{
    public List<sObjectWrapper> objList {get;set;}
    public testPageController(){
        objList  = new List<sObjectWrapper>();
        List<Account> acc = [select id,name,(select id,name from opportunities),(select id,name from contacts) from account where id =: '00128000003Kgdj' LIMIT 1];
        for(Contact con : acc[0].contacts){
            objList.add(new sObjectWrapper(con));
        for(Opportunity opp : acc[0].opportunities){
            objList.add(new sObjectWrapper(opp));
    public class sObjectWrapper{
        public SObject obj{get;set;}
        public sObjectWrapper (SObject obj){
            this.obj = obj;

VF Page : 

<apex:page controller="testPageController">
  <apex:repeat value="{!objList}" var="obj">

This will display all the opportunites and contacts related to a account with Id  = '00128000003Kgdj'. You can easliy make it dynamic. If you dont want the wrapper class, you can easily create 2 list , 1 for contact and 2nd for opportunity and loop through them on page and can display them.