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
ManidManid 

Anyone have idea about below question

i have one wrapper class in tha class two data members account and list contacts.
and i have list of wrapper class.i want to show list of wrapper in vf page.But it showing error .How to solve this Pls anyone help me.
Sandeep WaliaSandeep Walia

Hi Manid,

Can you pls share the code.

ManidManid
wrapper class
---------------
public class AccountWrapper {
    public account acc {get;set;}
    public list<contact> con {get;set;}
}


public class SetExamle6 {

    public list<AccountWrapper> acccon  {get;set;}
    
    public SetExamle6(){
        list<account> accs=[select name,industry,rating,(select lastname,phone from contacts) from account];
             for(account a:accs){
            AccountWrapper aw=new AccountWrapper();
            aw.acc=a;
            aw.con=a.contacts;
            acccon.add(aw);
}      
    }
}

i want to show list of accountwrapper account and contact records in a table


 
Sandeep WaliaSandeep Walia
Hi Manid,

Here is the updated controller:
public class SetExamle6 {

    public list<AccountWrapper> acccon{get;set;}
    
    public SetExamle6 (){
        list<account> accs=[select name,industry,rating,(select lastname,phone from contacts) from account];
        accCon = new List<AccountWrapper>();//Instantiating List of AccountWrapper
             for(account a:accs){
            AccountWrapper aw=new AccountWrapper();
            aw.acc=a;
            aw.con=a.contacts;
            acccon.add(aw);
            }
            system.debug(accCon);      
    }
    public class AccountWrapper {
        public account acc {get;set;}
        public list<contact> con {get;set;}
    }
}

Notice that I have instantiated the list of account wrapper.

You didn't share the code for your VF Page, here is how it's basic structure should be like:
<apex:page controller="SetExamle6 ">
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Table Example</h1>
  <table border="1">
      <tr>
          <th>
              Name
          </th>
          <th>
              Industry
          </th>
          <th>
              Related Contacts
          </th>
       </tr>
      <apex:repeat value="{!acccon}" var="wrapper">
          <tr>
              <td>
                  <apex:outputText value="{!wrapper.acc.name}"/>
              </td>
              <td>
                  <apex:outputText value="{!wrapper.acc.industry}"/>
              </td>
              <td>
                  <table>
                    <apex:repeat value="{!wrapper.con}" var="contacts">  
                      <tr>
                          <apex:outputText value="{!contacts.lastname}"/>
                      </tr>
                      </apex:repeat>
                  </table>
              </td>
          </tr>
      </apex:repeat>
  </table>
  
</apex:page>

and here is the output:
User-added image

Hope this helps,
Sandeep
 
ManidManid
Thanks it works.Can we get the contac records with out using the another repeat or datatable.