8

Good day everyone,

I have created a batch process. Let say I have thousands of records to process. Now what i want is when there is an error encounter or some problem found in the data during the batch process, I want to stop or abort the batch process. Is it possible ? thank you.

9

I've never tried it, but I don't see anything in the System.abortJob documentation that says it doesn't work when called from the batchable so try:

public void execute(Database.BatchableContext bc, List<SObject> scope) {
    try {
        ...
    } catch (Exception e) {
        // Report errors here
        System.abortJob(bc.getJobId());
    }
}

I assume that making this call will also stop the finish method being called so you will have to do any error reporting immediately before the call.

  • 1
    I've tried it and i think its working . Thank you. – Hope Jul 17 '15 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.