You need to sign in to do that
Don't have an account?
Rajesh N
List 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?
You will not be able to display it as a sObject on vf page. Visualforce page will not be able to interprete sObject type at runtime. Also it is quite possible that you might not have same field on all objects.
If you are planning to view differnt object properties on vf page, make use of warpper class to warpp the properties and display it on vf page.
Here is example how you can use wrapper to dispaly various object records :
Thanks,
N.J
All Answers
I have answered your question in https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=906F0000000AgTRIA0 (https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Developer_Forums&criteria=OPENQUESTIONS&id=906F0000000AgTRIA0) thread
You can achieve this with the help of "Sobject" or "Generic object" of salesforce.
Please see the links below for reference:
http://www.salesforce.com/us/developer/docs/apex_workbook/Content/apex6_1.htm
https://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SObjects_accessing_fields.htm
Please mark as best answer if it solves your problem.
Regards,
Grazitti Team,
www.grazitti.com
Unable to display them in VF page.
Controller
public class Innerlst1 {
public list<sObject> lstObject { get; set; }
public Innerlst1(){
list<sObject> lstObject = new list<sObject>();
Account a = new Account();
sObject s = [SELECT Id, Name FROM Account LIMIT 1] ;
lstObject.add((Account)s);
contact c = new contact();
sObject s1 = [SELECT Id, lastname FROM contact LIMIT 1];
lstObject.add((contact)s1);
}
}
VF page
----------
<apex:page controller="Innerlst1" >
<apex:pageBlock >
<apex:pageBlockTable value="{!lstObject}" var="lst">
<apex:column value="{!lst.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Thanks
Rajesh.
You will not be able to display it as a sObject on vf page. Visualforce page will not be able to interprete sObject type at runtime. Also it is quite possible that you might not have same field on all objects.
If you are planning to view differnt object properties on vf page, make use of warpper class to warpp the properties and display it on vf page.
Here is example how you can use wrapper to dispaly various object records :
Thanks,
N.J
Thanks
Rajesh.