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
Rahul Singh 1384Rahul Singh 1384 

Put record in a list after some processing from two other lists.

Hello Friends,

I have a 3 Lists of Account 'acclist1' , 'acclist2', & 'acclist3'
'acclist1' has 3 records.
'acclist2' has 2 records which are also present in 'acclist1'.

and I have a third list 'acclist3' in which i want to add that record which is not present in 'acclist2'.
So How can i acheive this scenario in Apex Code?

Any Example or Code assitance will be greatly appreciated.
VamsiVamsi

convert all of them to set instead of list.

set<Account> set1 = new set<Account>();
set<Account> set2 = new set<Account>();
set<Account> set3 = new set<Account>();  /// set or list both are fine for 3rd one 

// now iterate throug second one and get records not in set 1
for(account ac : set2)
{
   if(!set1.contains(ac))
{
 set3.add(ac);

}
}