You need to sign in to do that
Don't have an account?
Abilash.S
How to add multiple wrapperlists into single list
Hi,
I have written three seperate wrapper classes for three different Sobjects. I need to add three wrappers into single list. Please help me how to do
---------------------------------------------
@Auraenabled(cacheable=true)
public static List<sObject> wrapData() {
List<WrapperContact> wrapContact = new List<WrapperContact>();
List<WrapperAccount> wrapAccount = new List<WrapperAccount>();
List<WrapperLead> wrapLead = new List<WrapperLead>();
for(Contact ct : [select id, name from Contact LIMIT 10]){
wrapContact.add(new WrapperContact(ct));
}
for(Account acct : [select id, name from Account LIMIT 10]){
wrapAccount.add(new WrapperAccount(acct));
}
for(Lead ld : [select id, name from Lead LIMIT 10]){
wrapLead.add(new WrapperLead(ld));
}
system.debug('wrapContact'+wrapContact);
system.debug('wrapAccount'+wrapAccount);
system.debug('wrapLead'+wrapLead);
// s.add(wrapContact);
// s.add(wrapAccount);
// s.add(wrapLead);
List<SObject> s = new List<SObject>{
new Contact(),
new Account(),
new Lead()
};
// system.debug(s);
List<sObject> objects = new List<sObject>();
objects.addAll((List<sObject>)(wrapContact));
objects.addAll((List<sObject>)(wrapAccount));
objects.addAll(wrapLead);
return objects;
}
public class WrapperAccount{
@Auraenabled
public Account ac{get;set;}
public WrapperAccount(Account acct){
ac=acct;
}
}
public class WrapperContact{
@Auraenabled
public Contact cont{get;set;}
public WrapperContact(Contact ct){
cont=ct;
}
}
public class WrapperLead{
@Auraenabled
public Lead ldd{get;set;}
public WrapperLead(Lead ld){
ldd=ld;
}
}
------------------------------------------------------------
I have written three seperate wrapper classes for three different Sobjects. I need to add three wrappers into single list. Please help me how to do
---------------------------------------------
@Auraenabled(cacheable=true)
public static List<sObject> wrapData() {
List<WrapperContact> wrapContact = new List<WrapperContact>();
List<WrapperAccount> wrapAccount = new List<WrapperAccount>();
List<WrapperLead> wrapLead = new List<WrapperLead>();
for(Contact ct : [select id, name from Contact LIMIT 10]){
wrapContact.add(new WrapperContact(ct));
}
for(Account acct : [select id, name from Account LIMIT 10]){
wrapAccount.add(new WrapperAccount(acct));
}
for(Lead ld : [select id, name from Lead LIMIT 10]){
wrapLead.add(new WrapperLead(ld));
}
system.debug('wrapContact'+wrapContact);
system.debug('wrapAccount'+wrapAccount);
system.debug('wrapLead'+wrapLead);
// s.add(wrapContact);
// s.add(wrapAccount);
// s.add(wrapLead);
List<SObject> s = new List<SObject>{
new Contact(),
new Account(),
new Lead()
};
// system.debug(s);
List<sObject> objects = new List<sObject>();
objects.addAll((List<sObject>)(wrapContact));
objects.addAll((List<sObject>)(wrapAccount));
objects.addAll(wrapLead);
return objects;
}
public class WrapperAccount{
@Auraenabled
public Account ac{get;set;}
public WrapperAccount(Account acct){
ac=acct;
}
}
public class WrapperContact{
@Auraenabled
public Contact cont{get;set;}
public WrapperContact(Contact ct){
cont=ct;
}
}
public class WrapperLead{
@Auraenabled
public Lead ldd{get;set;}
public WrapperLead(Lead ld){
ldd=ld;
}
}
------------------------------------------------------------
Can you kindly check this link if this what you are looking for :-
https://salesforce.stackexchange.com/questions/349736/how-can-i-add-different-objects-in-one-list
Kindly mark it as the best answer if it works for you.
Thanks & Regards,
Priya Ranjan