You need to sign in to do that
Don't have an account?
how to compare two list in apex class
I have Two List of object records.
List<Account> accList1 = {1st record, 2nd record, 3rd record, 4th record};
List<Account> accList2 = {1st record, 3rd record};
I have another List<Account> accList3 = new List<Account>()
now I want to compare both List list1 and list2, get the record from list1 which is not present in list2 and add to List3.
List<Account> accList1 = {1st record, 2nd record, 3rd record, 4th record};
List<Account> accList2 = {1st record, 3rd record};
I have another List<Account> accList3 = new List<Account>()
now I want to compare both List list1 and list2, get the record from list1 which is not present in list2 and add to List3.
Something like this would work.
All Answers
Something like this would work.
Hi OM Deshmane,
please find the below solution
If you find this helpful mark it as the best answer.
Use nested for loop for comparing these Account records and use id as a unique key.
for(Account a : accList1){
if(!accList2.contains(a)){
accList3.add(a);
}
}
try this.
ref: http://peterknolle.com/apex-list-contains/
Its working.
https://indiateerresult.blogspot.com/