Finding Error Records in database.insert
list<account> acc = new list<account>();
acc.add(new account(name = 'mahi',phone = '090909'));
acc.add(new account(name = 'mahit',phone = '0909090'));
acc.add(new account(name = null));
acc.add(new account(name = 'mahitf',phone = '09039090'));
acc.add(new account(name = ''));
database.SaveResult[] results = database.insert(acc,false);
// Check results.
for (Integer i = 0; i < results.size(); i++) {
if (results[i].isSuccess()) {
System.debug('Successfully created ID: '+ results[i].getId());
} else {
System.debug('Error: could not create sobject '+ 'for array element ' + i + '.');
System.debug(' The error reported was: '+ results[i].getErrors()[0].getMessage() + '\n');
}
}
nice
ReplyDelete