So I have run a apex class that makes a callout to a external application. So I triggered the callout in SFDC and I have gotten hundreds of System Exception Read Timed Out emails. I have went to Apex Jobs, and have clicked Abort but they just keep coming. I can not make any changes to my apex class because it says the class is still being used by the class.

How do I stop the queue from regenerating new exceptions? Do I have to create another apex class that calls system.abortjob(IdofException)?

  • 1
    Is this a scheduled Apex job, a Queueable chain, Batch Apex...?
    – David Reed
    Jun 15, 2018 at 21:25
  • Yes I believe it is a batch Apex
    – nameishi
    Jun 15, 2018 at 21:26

2 Answers 2


How I've managed this in the past, e.g. because of an infinite recursive call, is to force a lock on the AsyncApexJob table; this allows me to kill the job even if it's running very quickly:

for(AsyncApexJob job:[SELECT Id FROM AsyncApexJob WHERE Status IN ('Holding','Queued','Preparing','Processing') FOR UPDATE]) {

Note: Doing this will kill any and all pending jobs, so you may need to modify this code to prevent cancelling future methods, etc.

You can run this from Execute Anonymous, which will save you the trouble of a deployment just to kill the job.

  • where would I put this code?
    – nameishi
    Jun 15, 2018 at 21:29
  • @nameishi Force.com IDE, Developer Console, salesforce DX CLI, wherever. You want to run this under "Execute Anonymous" (e.g. Developer Console would be "Ctrl-E"). Once executed, it should halt all pending future executions.
    – sfdcfox
    Jun 15, 2018 at 21:30
  • @nameishi Also, there was a typo, sorry. Fixed.
    – sfdcfox
    Jun 15, 2018 at 21:31
  • I get Line: 2, Column: 1 System.StringException: You can't abort scheduled Apex jobs by calling System.abortJob with an AsyncApexJob ID. Call System.abortJob with the parent CronTrigger ID.
    – nameishi
    Jun 15, 2018 at 21:35
  • @nameishi Add a criteria for your class: for(AsyncApexJob job:[SELECT Id FROM AsyncApexJob WHERE Status IN ('Holding','Queued','Preparing','Processing') AND ApexClass.Name = 'XYZ' FOR UPDATE]) {
    – sfdcfox
    Jun 15, 2018 at 21:37

I had to go to Freeze the user that was causing the Read Time out continuous loop.
In my Code I setTimeout(120000); and added a try catch block to prevent this from happening again.

You must log in to answer this question.

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