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
Preya VaishnaviPreya Vaishnavi 




I need to display values from different objects in a table.And these objects have no relationship between them directly.So i went for wrapper classes.But how to use a wrapper class for displaying values from different object in the visualforce page?


for eg: i need to display accounts in the account name column and the related contacts' name,phone,email in the contact name ,phone,email columns respectively in a table.


Any code that is already developed would be handy .....




A wrapper class is simply a custom class that encapsulates multiple items of data.  Thus is this case your class would contain an account and an associated list of contacts.  That said, if it is really an account and its contacts you should be able to use a relationship query to retrieve the account(s) and associated contacts in the regular sobject structure.




List<Account> accs=[select id, Name (select id, Name from Contacts)];


and you can use this in the page as:


<apex:repeat value="{!accs}" var="acc">
  <apex:repeat value="{!acc.Contacts}" var="cont">


Preya VaishnaviPreya Vaishnavi



Thanks for the reply.


BTW, the objects that i am concerned about are custom objects and these custom objects have no relationship with them.I need to display  some values of these objects in a table .I am using apex:pageblock table for the same and the value attribute in the pageblock table comes from the wrapperclass list.


You can do that also - your wrapper class will contain the group of custom objects that you want to display.  When you iterate the list of wrapper classes,  you can use fields from the custom objects enclosed as column values.  If your situation is more complex than that, can you elaborate?

Preya VaishnaviPreya Vaishnavi



I need to display a table of values like


the first column contains my accountname/product line name,second column contains invoice amount for the month july,third column--invoice amount for the month august,fourth column-invoice amount for the month august,fifth column--opportunity revenue,and remaining five columns values from different custom objects.first row contains account name and the corresponding total invoice values and so on.. as specified above,second row contains the products under account name and the corresponding invoice value and so on...


Any pointers would be appreciable




So you'll need to create a wrapper class that can contain all of these distinct values.  It doesn't make the wrapper class concept any more complex, it just changes the amount of work you have to do in terms of queries.


There's an example of using a wrapper class where the row is simply a list of text values on my blog at: