+ Start a Discussion

Handling an aborted batch


I have a batch process which does some clean up in the finish(...) method.  However, if the user aborts the job (e.g. they go to the list of Apex jobs and click "Abort"), this code is not executed.

I was wondering if there was any way to handle the abort event so that my clean up code is still called?


No, you would have to do something like write a scheduled job that looks for Aborted jobs and then run your code.  Alternatively you could make your clean up code a static class level method somewhere and call that manually when you abort.