I am trying to connect specific records that fail to delete in my batch job to their error messages. I thought my solution was working, but I checked the size of .getErrors() and it's size 1. My test class is set up so 50 records fail, so I would think the size of .getErrors() would be 50. How is the .getErrors() array populated?

1 Answer 1


When you are calling Database.delete it is returning a List of Database.DeleteResult records if you are doing it to a list.

There are several things that could cause only 1 record to be returned here.

1) If you are calling Database.delete inside a query on each individual record, you will only get 1 error returned.

for (Account acc: scope)
  Database.DeleteResult result = Database.delete(acc);
  if (!result.success)
    //This is only asking for all of the errors on a single record here
    List<Database.Error> errors = result.getErrors();

2) You are looking at a single result instead of all of the results.

List<Database.DeleteResult> results = Database.delete(scope);
for (Database.DeleteResult result: results)
  if (!result.isSuccess())
    //Again, this is only for a single record
    Database.Error errors = result.getErrors();

It's harder to tell for sure what is going on though unless you show us what you have done.

  • 1
    Right; .getErrors() only applies to one row of the DML operation. To get the total number of errors in the operation, you will have to check all the results and count up how many had errors on them. Oct 20, 2014 at 21:05

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.