Is the 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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0