finish() method of an Apex Batch class called when a user aborts the batch during startup or processing? Is there a way to find out who aborted it?
Is the finish() method of an Apex Batch class called when a user aborts the batch during startup or processing?
No, it isn't in both scenarios. According to Salesforce documentation:
The finish method is called after all batches are processed. Use this method to send confirmation emails or execute post-processing operations.
That means that if at least one batch wasn't executed we will not enter
finish() method. To double check that nothing has changed I made a simple batch job and tested. Code from
finish() method was not executed.
Is there a way to find out who aborted it?
We are not able to check this. Perhaps Salesforce Support can find such information in their server logs. You can try.
Just as a side note, maybe that will be your case even though you were asking about manual aborting. In our company we had some issues with batch jobs that were aborted everyday. We were pretty sure that they weren't aborted by any user. So we raised a support Case to SF Support Team to investigate this and it turned out that it was aborted by system not a user due to a time-out error on of the SOQL queries.
Hope that helps.