2

I want to roll back a complete batch related transaction if there is any exception while processing anywhere during batch execution

I can roll back that specific transaction, but not sure if I can rollback complete batch process.

Thanks,

Ray

1 Answer 1

0

If you don't catch exceptions or handle exceptions and use DML statements without partial DML like database.update your whole transaction by default will roll back when there is failure.

If you want to roll back previous batches,keep a flag or an identifier and in catch block just reverse the operation.

Update

An example could be to update the flag.In the finish method you can uncheck the flag to unmark all.

3
  • 1
    I think "reverse the operation" merits the caution that it may not be easy to do and maybe an example.
    – Keith C
    Commented Aug 6, 2015 at 12:58
  • Hey Mohit, by reversing the operation do you mean undo all the processes that I have already done in previous batches? As that is going to be very complicated and will not be feasible. I am more thinking around doind a proper rollback to an initial save point if possible
    – SEuser
    Commented Aug 6, 2015 at 18:04
  • Kaushik do you want to revert whole process or a specific batch only .If specific batch as already mentioned just throw the exception so that salesforce dont commit anything .Thanks Commented Aug 6, 2015 at 18:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .