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
Radical_arjoRadical_arjo 

System.abortJob(sc.getTriggerId()) is not working

Hi All,

 

I am trying to abort a scheduled job using System.abort() method. I am using getTriggerId() to get the id of the scheduled job. The line gets executed without any errors and i ahve confirmed the same in debug logs. However the job is not getting aborted. This functionality was working a few days back, but currently stopped working it seems.

 

Can anyone provide any help on this????

Ranjeet Singh (SFDC Developer)Ranjeet Singh (SFDC Developer)

Use System.abortJob Method. this must be work

Like your code is:

global void execute(SchedulableContext sc){}

 

you can get and track your scheduler method using SchedulableContext  variable.

use: System.abortJob(sc.getTriggerId());

Please try this approch..if it is not working then pase your code on discusion ..we will try to give the possible approch.

 

Radical_arjoRadical_arjo
global class SchClass implements Schedulable {
global void execute(Schedulable Context sc){ 
try { CustomSetting__c Flag = CustomSetting__c.getValues(Label.FlagVal); boolean flag = obj.FlagVal__c; if(!flag){ obj.FlagVal__c = true; update obj; calling batch here.... CustomeSetting2__c obj1 = CustomeSetting2__c.getValues(Label.RecType); String currentRecordType = obj1.AccRecordType__c; If(currentRecordType == 'Partner'){ system.abortJob(sc.getTriggerId()); } } }catch(Exception e){ system.debug('****Exception message ****' + e.getMessage()); } }
}

 I have used the abortJob function... Sorry for the typo in my previous post. I have checked the debug logs and i can see the code hitting the abortjob function. However the scheduled job still remains in the queue. 

The abortJob method is working fine in other parts of the code... 

 

Thanks for your help

Blobo MoboBlobo Mobo

I had this problem when I got my girlfriend pregnant.

 

Seriously though, that is so strange.  Are you absolutely sure that it is not cancelled?   Check the return value of the sc.getTriggerId() method...   Run SOQL [Select Id, NextFireTime, State FROM CronTrigger WHERE Id = yourcrontriggerid]?  Is it actually cancelled?  Does the same thing happen if there are no other CronTriggers?

Radical_arjoRadical_arjo

Hi Blobo,

 

I am pretty sure that it is not getting deleted and my girlfriend is not pregnent... :).

 

I am suspecting that is there are any update statements before the system.abortJob() , it does not work, any other inputs are welcome.