Say, I have a list of 1000 records to be inserted. How to capture those records that failed to get inserted? I realize that I can use DMLException to get the error. But how to get a list of failed insertions. Here's a situation I created to demonstrate my requirement.
Account[] accts = new List<Account>();
for(Integer i=0;i<1000;i++) {
Account a = new Account(Name='Acme' + i, BillingCity='San Francisco');
accts.add(a);
}
Account accountToUpdate;
try
{
insert accts;
}
catch(DmlException e)
{
System.debug('An unexpected error has occurred: ' + e.getMessage());
}
Say record Acme50 and Acme62 didn't get inserted. How to get a list of failed records?