I am doing an insert using Database.Insert in a batch class as follows:

Database.SaveResult[] srList = Database.insert(clonedList, false);

for (integer i=0; i<srList.size(); i++) {

    system.debug('srList : '+i+' : '+srList[i].isSuccess());





When I check the debug logs, I see the code has not entered the srList loop.

I know there are some errors and records not inserted, but I am not getting the errorMap populated.

  • 4
    I suggest you add system.debug('clonedList= + clonedList) immediately before your insert; AFAIK the only way you would get zero results is if you inserted zero objects. – Keith C May 13 '14 at 9:58

You should only find this scenario (not entering the loop) when clonedList is empty.

Here's my own snippet of code I tested against and had no issues.

Update Case

source code:

List<Account> accounts = new List<Account>{new Account(), new Account(), new Account()};
Database.SaveResult[] saveResult = Database.update(accounts, false);

for(Database.SaveResult saveRes : saveResult) {
    if(!saveRes.isSuccess()) {
        for(Database.Error err : saveRes.getErrors()) {

And before anyone says anything with my update, I also did the same test with insert:

Insert Case

| improve this answer | |
  • The real repro case would be to also run it on an empty list. – Adrian Larson Mar 1 '17 at 21:23
  • I just tried it with an empty list as you suggested @AdrianLarson, but there was no debug statement. I still think NHK's variable is empty. – Double A Mar 1 '17 at 21:25
  • That's the point. That's exactly the problem the OP faced... – Adrian Larson Mar 1 '17 at 21:26
  • Got it, now i see why you edited my original post. Good looking out. – Double A Mar 1 '17 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.