Activity Forums Salesforce® Discussions How to perform rollback action in Salesforce, once a batch class is processed?

  • Kumar

    Member
    January 25, 2017 at 12:38 pm

    Hi Pranav,

    I am assuming that you want to rollback the batch process because of some error, in that case:

    Unfortunately the platform does not wrap a single Database transaction around the whole job. This is not possible due to the amount of data and length of the jobs (likely Oracles commit log would break internally anyway). So it breaks the job into chunks/scopes determined by a parameter on the Database.executeBatch method (defaults to 200 records). Each of these scopes is passed to your 'execute' method, this represents a single transaction and here you can rollback changes if needed. For more information see the documentation here.

    Given the above you have a few options to consider, though the most scalable is to ensure that your job can be re-run incrementally (only for records still not processed via a flag of some kind on the records being processed) once the errors have been addressed. If your data volumes are low enough you might be able to implement your rollback logic in your 'finish' method. You can refer to this post here for more info.

    Hope this helps.

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos