How to abort a long running future Apex job?
To abort long running batch, future or scheduled Apex jobs,
we can use System.abortJob() from the Developer Console (using execute anonymous window from menu dropdown) and pass the job id to this method - system.abortJob('...jobid...')
Steps you can use in Workbench/Devloper Console/UI:
Workbench:
Go to Workbench > select the Environment > Choose a lower API version to 32.0 > Enter username and password. > Go to Query | SOQL Query.
We need to run the following query to find a queued status scheduled or future Apex job id to abort-
SELECT ApexClassId,CompletedDate,CreatedById,CreatedDate,ExtendedStatus,Id,JobItemsProcessed,JobType,LastProcessed,LastProcessedOffset,MethodName,NumberOfErrors,ParentJobId,Status,TotalJobItems FROM AsyncApexJob where status = 'queued'
Once we get the jobId that we need to delete:
Go to Utilities > Apex Execute > Replace text "JobID" in the following line of code with the Job Id you found in the query and then click Execute.
System.abortJob('JobID');
With this, the scheduled Apex job should get deleted.
Developer Console:
Developer Console > Debug > Open Execute Anonymous Window.
We need to run the following query to find the scheduled or future Apex job id to delete:
SELECT ApexClassId,CompletedDate,CreatedById,CreatedDate,ExtendedStatus,Id,JobItemsProcessed,JobType,LastProcessed,LastProcessedOffset,MethodName,NumberOfErrors,ParentJobId,Status,TotalJobItems FROM AsyncApexJob where status = 'queued'
Replace text "JobID" in the following line of code with the Job Id and then click Execute.
System.abortJob('JobID');
The scheduled or future Apex job should get deleted.
UI:
Setup > Search 'Scheduled' in the quick find box > Click Scheduled Jobs > Click on 'Del' link beside the scheduled job that we want to delete.
Resource(s): https://help.salesforce.com/
Comments
Post a Comment