You need to sign in to do that
Don't have an account?
harry63
How to combine two Lists
HI i have some selected contacts inone list and i have some selected contacts in other list.i want to display the selected contacts on a vf page. does any one tell me how to combine selected records in both lists.
It is very urgent
thanks in advance
To combine lists you can simply create a new list and add both your existing lists to it:
You can use the addall method as a more efficient way to combine your sublists, instead of the for loops.
This is code for Lead object same way you can do this with contact object.
List<Lead> L1 = new List<Lead>([select id,name,leadsource from Lead where leadsource='Phone Inquiry' limit 1] );
List<Lead> L2 = new List<Lead>([select id,name,leadsource from Lead where leadsource='Purchased List' limit 1]);
system.debug('$$$$$$$$$$$$$$$4' + L1[0].id);
system.debug('@@@@@@@@@@@@@@@@@' + L2[0].id);
List<Lead> MasterLead = new List<Lead>();
MasterLead.addall(L1);
MasterLead.addall(L2);
system.debug('#######3 ' + MasterLead[1].id);
Thans for reply.still not getting expected result.
contactlist and ccontactlist are the two lists containig some records.i want to add the selected records in that two lists.I am using wrapper class..Pleae help me very urgent
public void addcons()
{
{ integer j=0;
integer i=0;
for(cContact cc:contactList)
{{contactlist1.add(cc);
if(cc.selected==true)}}
{{
contactlist2.add(scc);
if(scc.selected==true)
}}
contactlist.clear();
contactlist.addall(contactlist1);
contactlist.addall(contactlist2);
note:contactlist is displaying only contactlist2 records.
Thans for reply.still not getting expected result.
contactlist and ccontactlist are the two lists containig some records.i want to add the selected records in that two lists.I am using wrapper class..Pleae help me very urgent
public void addcons()
{
{ integer j=0;
integer i=0;
for(cContact cc:contactList)
{{contactlist1.add(cc);
if(cc.selected==true)
}}
{{
contactlist2.add(scc);
if(scc.selected==true)
}}
contactlist.clear();
contactlist.addall(contactlist1);
contactlist.addall(contactlist2);
note:contactlist is displaying only contactlist2 records.
Have you tried adding some debug to your method to output information about contactlist (e.g. size) once you've added in each of the "sublists"? I can't see any reason why what you are doing isn't working.
You can combine two lists using apex this way:
List<Opportunity> OppList = new List<Opportunity>();
OppList.addAll(list1);
OppList.addAll(list2);
If you find your Solution then mark this as the best answer.
Thank you!
Regards
Suraj Tripathi