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
John T 4John T 4 

Display data from multiple objects in a VF page in one pageblocktable

I have a requirement to display records from 2 objects (Account & Contact) in a single pageblocktable in a VF page, Account records followed by Contact records.
I know that we can achieve this using a wrapper class, but all the examples I came across talked about displaying checkbox or displaying columns vertically(not horizontally) from different objects in a pageblocktable.

Would appriciate any pointers/code samples. Thanks!!

User-added image

 
Jerun JoseJerun Jose
Your wrapper class would have 4 string variables:
Object
Name
Phone
Email.

You will have to loop through the query results of the account object and cast the query results into this wrapper object and add them to a list.
After this, you will have to write another loop where you iterate through the contact object results and cast the query results into a wrapper object and add them to the same list.

You can then use that list in a pageblocktable in VF to display the combined query results. Give it a try and post your code below, we can work on refining it.