function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Scheduled apex job is not being removed from Scheduled Jobs list

I have an Scheduler class witch invokes a batch class, my scheduler invokes System.abortJob to stop it is own execution, but most of these scheduled jobs still remain in Scheduled Jobs list.


Here is my scheduler class.


global class MyScheduler implements Schedulable {
   public Set<Id> olisIds {get; set;}
   global void execute(SchedulableContext ctx) {
		MyBatch batch = new MyBatch();
		batch.listOfIds = olisIds;

The System methods documentation says the following about abortJob method:

Stops the specified job. The stopped job is still visible in the job queue in the Salesforce user interface.


But the accumulation of those scheduled jobs are causing an error and I am having to exclude them via interface.


Can anyone help me with it?


Thanks in advance.




Please verify if ctx.getTriggerId() is giving correct results.


After execution of the system.abbort method the job will continue its task and be terminated where it does not violate the data consistency.
In case of a job executing the batchable.start() method, the job is terminated after the start() call is done.

If the start() method in the batch job is time-consuming, and since only one job per an org at a time can execute the batachable.start() method, other jobs don't get a chance to be run.
But the jobs are dispatched properly one at a time, after abort is completed.

Troubleshooting steps -

1) Check the rows returned by Query Locator in the start() method of the batch job.
If the number of rows is getting larger, more requests to our Cursor servers would be required.
Since those requests are sent to the start() method, it would delay completing the start() method.

2) Check if start() method has nested queries.
This could also slow down the start() method processing.


I didnt check the result of getTriggerId() yet.


I dont think my problem is the batch class invoked by the scheduler, my problem is with the scheduler, it is not being removed from the scheduled job list.


Even so, thanks for your response.

Ranjith Kumar 229Ranjith Kumar 229
You should try this, it will  work.

for(CronTrigger delCron: [SELECT CronJobDetail.Name, CronExpression, OwnerId FROM CronTrigger WHERE CronJobDetail.JobType = '7' and State='EXECUTING']) {

Thanks & Regards
Ranjith Kumar M