You need to sign in to do that
Don't have an account?
srikforce
How to add elements of List 1 to List 2
I have created List 1 and List 2
after creating objects to 2 diff classes I have added some elements.
List1.add(obj1); // adding obj1 to the List 1
List2.add(obj2) // adding obj2 to the List 2
Return type for both the Lists are different...
now I would like to return List 2 on debug logs but List 2 should contains elements of both List 1 and List 2...
Please try to resolve this..
thank u so much ,,,,,
You can add List 1 and List 2 to a new List 3, as follows:
List<Account> ls1 = [Select name from Account limit 2];
System.debug('----------- ls1:' + ls1);
List<Contact> ls2 = [Select name from Contact limit 2];
System.debug('----------- ls2:' + ls2);
List<Sobject>ls3 = new List<Sobject>();
ls3.add((sobject)ls1[0]);
ls3.add((sobject)ls1[1]);
ls3.add((sobject)ls2[0]);
ls3.add((sobject)ls2[1]);
System.debug('----------- ls3:' + ls3);