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
Rajesh NRajesh N 

Lists of Different Types

I'm looking to create a single list of records of various sObject types using apex to display to a custom visualforce page. I'm wondering if there is a way to combine multiple objects (case, opportunity, account, etc) within a single list. If not, how do you append the second object to the first in a list using visualforce code? Is there a best practice?
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi,

You can use list of sObject as :
list<sObject> lstObject = new list<sObject>();
        
Account a = new account();
lstObject.add((sObject)a);
        
Contact c = new contact();
lstObject.add((sObject)c);


Thanks,
N.J
Deepak Kumar ShyoranDeepak Kumar Shyoran
I think you are looking for a Wrapper class. As we used them to wrap data from multiple object into a single unit and then used them on V.F page to display the data from different Object.

Please mark this post as a best solution to your problem to help others.
Rajesh NRajesh N
Not exactly, Deepak. Tried with Sobject to do the same thing. FInally used Wrappers.