[SalesForce] Scheduled Job does not execute. Though shows in GUI

I have a scheduled class that is seen and setup within the Gui. Setup->Monitoring->Scheduled Jobs
Schedule For Apex Job

It is set to run everday at 6PM. It shows started and next scheduled run. However, I started it over the weekend and have yet to receive any email from it. The Schedulable class being called is below.

global class DistiAutomationSchedule implements Schedulable {

global void execute(SchedulableContext SC){
    AccountPOSTExcelFile A = new AccountPOSTExcelFile();
    A.runDistiReports();
}

}

I can run the code withing the schedulable context using the Force.com IDE and Execute anonymously and it runs as it should.

AccountPOSTExcelFile A = new AccountPOSTExcelFile();
    A.runDistiReports();

Any help or next debug steps would be very much appreciated.

Best Answer

Per SFDC support below is their response that resolved the issue I was having.


I have investigated and found that the issue started happening after 13 because with summer 13 - Scheduled Apex jobs have an AysncApexJob row, this always stays in the Queued status until the job has no nextfiretime, then it gets marked completed, or if the job is aborted, then the AsyncApexJob row gets marked aborted as well. if it is a job that recurs indefinitely, then it will never get marked as completed. It will only get marked completed if after running the execute method, the cron trigger a nextfiretime of null.( see the summer 13 release note -page 229 https://org62.my.salesforce.com/help/doc/en/salesforce_summer13_release_notes.pdf).

Please try to to abort the current scheduled job in the sche duled class and then schedule it after 1 minute. Please see this sample code.

NOTE This is sample code and not ready for production.

global class SFDCselfReschedulingClass implements Schedulable{ 

// Execute method 
global void execute(SchedulableContext SC) { 

// Code to be executed when the schedule class wakes up 

// this section of code will abort the current schedule job 
try { 
system.abortJob(sc.getTriggerId()); 
} catch (exception e) {system.debug('#### schedule job exception while aborting:' + e);} 


// reschedule the job 
system.debug('#### schedule job executing'); 
scheduleNow(); 

} 

global static void scheduleNow() { 

// this section of code will schedule the next execution 1 minute from now 
datetime thisTime = system.now().addSeconds(15); 
integer minute = thisTime.minute(); 
integer second = thisTime.second(); 
integer hour = thisTime.hour(); < br/>integer year = thisTime.year(); 
integer month = thisTime.month(); 
integer day = thisTime.day(); 

String timeStamp = second + ' ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ? ' + year; 
string jobName = 'SFDCselfReschedulingClass'; 

SFDCselfReschedulingClass p = new SFDCselfReschedulingClass(); 
system.schedule(jobName, timeStamp , p); 

} 

} 

I then altered my code to work with the new format provide above:

global class DistiAutomationSchedule implements Schedulable {

    // Execute method 
    global void execute(SchedulableContext SC) { 

    // Code to be executed when the schedule class wakes up 
        AccountPOSTExcelFile.runDistiReports();



    // this section of code will abort the current schedule job 
    try { 
    system.abortJob(sc.getTriggerId()); 
    } catch (exception e) {system.debug('#### schedule job exception while aborting:' + e);} 


    // reschedule the job 
    system.debug('#### schedule job executing'); 
    scheduleNow(); 

    } 


    global static void scheduleNow() { 

    // this section of code will schedule the next execution 1 minute from now 
    datetime thisTime = system.now().addHours(24); 
    integer minute = thisTime.minute(); 
    integer second = thisTime.second(); 
    integer hour = thisTime.hour(); 
    integer year = thisTime.year(); 
    integer month = thisTime.month(); 
    integer day = thisTime.day(); 

    String timeStamp = second + ' ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ? ' + year; 
    string jobName = 'Disti Automation Schedule'; 

    DistiAutomationSchedule p = new DistiAutomationSchedule(); 
    system.schedule(jobName, timeStamp , p); 

    }


}
Related Topic