
Hi Pooja, I have done few modification in your code to reduce for loop
Hope this help you.ThanksShwetaList<Account> accList1=new List<Account>();
Account acc1=new Account();
acc1.Name='Falcon1';
Account acc2=new Account();
acc2.Name='Falcon1';
Account acc3=new Account();
acc3.Name='Falcon2';
Account acc4=new Account();
acc4.Name='Falcon3';
accList1.add(acc1);
accList1.add(acc2);
accList1.add(acc3);
accList1.add(acc4);
Map<string,Account> newAccRecMap = new Map<string,Account>();
for(account acc : accList1){
newAccRecMap.put(acc.Name,acc);
}
List<Account> aList2=[select ID,Name from Account where Name IN: newAccRecMap.keySet() Limit 50000];
if(aList2.size() > 0){
for(account acc : aList2){
if(newAccRecMap.containsKey(acc.Name)){
newAccRecMap.remove(acc.Name);
}
}
}
Database.Insert(newAccRecMap.values(),false);