I have implemented the batch which is executed from apex controller. Now, if one job of the batch fails (due to some exception), I need to rollback the changes not only for that job but for all the jobs in that batch which have executed.
I tried stateful batch with declaring the Savepoint() globally and initializing it in the execute() method, such that it will be initialized only once. Then I am rolling back from the catch block. But I am getting the run time error as System.SerializationException: Not Serializable: System.Savepoint
Another approach is to delete all the records from the finish() method, but since that object's trigger as some heavy processing in AfterDelete context. So, I might get CPU Time Limit exception.
Please suggest any alternative solution.