5

Usually when I write a class that implements Database.Batchable I end up saving errors in a variable(s) to sort through in the finish method and send out something about successes and failures. This time I decided to save all of my Database.SaveResult's in a collection and iterate through those in my finish method.

However, when I tried doing this I kept getting a hung job and one of my SerialBatchApexRangeChunkHandler's was failing with the following error:

Internal Salesforce.com Error

Class (errors):

global class AnnualAccountRebase implements Database.Batchable<sObject>, Schedulable, Database.Stateful {
    global List<Database.SaveResult> saveResults = new List<Database.SaveResult>();

    global void execute(Database.BatchableContext BC, List<Account> scope) {
        //do stuff to scope
        //inside try catch
        saveResults.addAll(Database.update(scope, false));
    }

    global void finish(Database.BatchableContext BC) {
        for (Database.SaveResult result : saveResults) System.debug(result);
    }
}

But if I change the variable to a List<String> type and get the data I want from the SaveResult's everything is fine.

Class (works):

    global class AnnualAccountRebase implements Database.Batchable<sObject>, Schedulable, Database.Stateful {
        global List<String> errors = new List<String>();

        global void execute(Database.BatchableContext BC, List<Account> scope) {
            //do stuff to scope
            //inside try catch
            List<Database.SaveResult> saveResults = Database.update(scope, false);

            for (Database.SaveResult saveResult : saveResults) {
            if (!saveResult.isSuccess()) {
                for (Database.Error e : saveResult.getErrors()) {
                    errors.add(e.getMessage());
                }
            }
        }
    }

    global void finish(Database.BatchableContext BC) {
        System.debug(errors);
    }
}

I also tried marking the first collection (SaveResult) as transient with no success.

Dug around for a while but could not figure out why this is happening. Perhaps my 'Google-Fu' is weak? Any insight would be appreciated.

4
  • I just tried a most basic version of this and got no internal error and the SaveResult objects appeared in the debug log from the finish. Perhaps the problem relates to specific data and it working after changing the list type was just a coincidence? Database.SaveResult is documented as (JSON) serializable in JSON Support.
    – Keith C
    Mar 17, 2016 at 21:23
  • maybe when there is an error, Database.SaveResult isn't serializable (I'm hypothesizing here); note also global is not required unless you are doing a managed package though why that would matter in this case.
    – cropredy
    Mar 17, 2016 at 22:10
  • @cropredy I don't think that is it because I then tried it with a Database.Error collection, which isn't serializable, and I got the serializable error. Mar 17, 2016 at 22:49
  • @KeithC I was using two Account records in my test class and putting some 'bad' data on one so I would have 1 fail and 1 update. Mar 18, 2016 at 18:20

1 Answer 1

1

You need to contact Salesforce and tell them you got an error at this time.., or cause the error to happen again so you can get an exact time.. They will be able to see the error that is actually happening in the DB and will be able to point you to the issue..

I've had this happen to me and it was actually a workflow rule that was cause it to blow up, may not be your case tho

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .