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
Devaraj 7Devaraj 7 

how to display multiple obects fields in single pageblock table.

iam just able to seen headers only i have data but iam unable to seen in pageblock table.
according to my knowledge that is correct only but where is the problem iwant to know

my vf page 


<apex:page controller="Multipleobjwrapper">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockTable value="{!wrplst}" var="w">
                    <apex:column headervalue="AccountName" value="{!w.acc.name}" />
                    <apex:column headervalue="ContactName" value="{!w.con.name}"/>
                    <apex:column headervalue="OpportunityName" value="{!w.opp.name}"/>
                    <apex:column headervalue="LeadName" value="{!w.led.name}"/>
                    <apex:column headervalue="CreditCardName" value="{!w.crd.name}"/>
                    <apex:column headervalue="Employee" value="{!w.emp.name}"/>
                    <apex:column headervalue="Student" value="{!w.stu.name}"/>
                    <apex:column headervalue="faculty" value="{!w.fac.name}"/>
                    <apex:column headervalue="paymentName" value="{!w.pay.name}"/>
                    <apex:column headervalue="pharmacyName" value="{!w.phm.name}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>




public class Multipleobjwrapper {
    public list<Account>      acclst{get; set;}
    public list<Contact>      conlst{get; set;}
    public list<Opportunity>  opplst{get; set;}
    public list<Lead>        ledlst{get; set;}
    public list<CreditCard__c>  crdlst{get; set;}
    public list<Employee__c>    emplst{get; set;}
    public list<Student__c>     stdlst{get; set;}
    public list<faculty__c>  faclst{get; set;}
    public list<payment__c>  paylst{get; set;}
    public list<pharmacy__c>  phmlst{get; set;}
    public list<Mywrapper> wrplst{get; set;}
    
    
    public Multipleobjwrapper(){
        acclst=[select Id,name from Account];
        system.debug('accounts'+acclst);
        conlst=[select id,name from Contact];
        opplst=[select id,name from Opportunity];
        ledlst=[select id,name from Lead];
        crdlst=[select id,Name__c from CreditCard__c];
        emplst=[select id,Lastname__c from Employee__c];
        stdlst=[select id,Name from Student__c];
        faclst=[select id,Name from faculty__c];
        paylst=[select id,Name from payment__c];
        phmlst=[select id,Name from pharmacy__c];
        
        wrplst=new list<Mywrapper>();
  
        for(integer i=0; i<10; i++)
        {
                        if(wrplst.size()!=0)
            {
          
                   wrplst.add(new Mywrapper (acclst[i],conlst[i],opplst[i],ledlst[i],crdlst[i],emplst[i],stdlst[i],faclst[i],paylst[i],phmlst[i]));
           
                   
                
            }
        }
    }
    
    public class Mywrapper{
        public Account acc{get; set;}
        public Contact con{get; set;}
        public Opportunity opp{get; set;}
        public Lead led{get; set;}
        public CreditCard__c crd{get; set;}
        public Employee__c emp{get; set;}
        public Student__c stu{get; set;}
        public faculty__c fac{get; set;}
        public payment__c pay{get; set;}
        public pharmacy__c phm{get; set;}
        
        public Mywrapper(Account a,Contact c,Opportunity o,Lead l,CreditCard__c cr, Employee__c e,
                         Student__c s,faculty__c f,payment__c p,pharmacy__c ph)
        {
            acc=a;
            con=c;
            opp=o;
            led=l;
            crd=cr;
            emp=e;
            stu=s;
            fac=f;
            pay=p;
            phm=ph;
            
        }
    }
    
    

}






 
sfdcMonkey.comsfdcMonkey.com
hi devraj ,
you have need to chnage the if condition in your apex class in for loop, use for loop code :

 for(integer i=0; i<10; i++)
                        if(acclst.size()> i && conlst.size()> i && opplst.size()> i && ledlst.size()> i && crdlst.size()> i && emplst.size()> i && stdlst.size()> i && faclst.size()> i && paylst.size()> i && phmlst.size()> i)
            {
          
                   wrplst.add(new Mywrapper (acclst[i],conlst[i],opplst[i],ledlst[i],crdlst[i],emplst[i],stdlst[i],faclst[i],paylst[i],phmlst[i]));
           
                   
                
            }
        {
        }


i hope it helps you.
  Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com


 
Suraj TripathiSuraj Tripathi
Hi Devraj,
Below is a code for your requirement. I have used a custom object 'Account' and 'Contact'.

Visualforce page :
<apex:page controller="wrappertest">
  <apex:form>
    <apex:pageBlock> 
      <apex:pageBlockTable value="{!listofdata}" var="abc">
            <apex:column headerValue="Contact First Name">
                <apex:inputField value="{!abc.theContact.firstname}"/>
            </apex:column>
            <apex:column headerValue="Contact Last Name">
                <apex:inputField value="{!abc.theContact.lastname}"/>
            </apex:column>
            <apex:column headerValue="Account Name">
                <apex:inputField value="{!abc.theAccount.name}"/>
            </apex:column>
      </apex:pageBlockTable>
    </apex:pageBlock>
  </apex:form>
</apex:page> 

Apex Controller :

public class wrappertest{
  public List<aTableRow> listofdata { get; set; }
  public class aTableRow { 
    public Contact theContact { get; set; }
    public Account theAccount { get; set; }
    
    public aTableRow(Contact c,Account a,Boolean b) {
      theContact = c;
      theAccount = a;
     
    }
  }

  public wrappertest() {
    listofdata = new List<aTableRow>();
    for(Contact c:[select id,firstname,lastname,account.id,account.name from contact limit 10]) {
      listofdata.add(new aTableRow(c,c.account,false));
    }
  }
}


Screenshot :
User-added image

Make changes in the wrapper class and code according to your requirement.


Hope it Helps you. Please mark this as solved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Regards ,
Suraj
Devaraj 7Devaraj 7
Sorry