6

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.

6

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); 

    }


}
| improve this answer | |
  • Hi it means time stamp is static always. We can not change it from developer console. Or Can we schedule the class from developer console so that we can change time of job in our own way. Please let me know are you going to provide any value to 'timeStamp' variable in the class itself to schedule it. – Rohit Jun 17 '14 at 8:13
1

If you look in Setup | Monitoring | Apex Jobs you will see the results of jobs which have run. You can see there if there is an error message associated with the last scheduled run of this job. It's a good place to start investigations.

If your apex jobs view is very busy (lots of jobs) create a view to limit it to just the specific class you are interested in.

| improve this answer | |
  • Thanks for the info. I checked the Apex Jobs link and it shows my job, but status is Queued. Total Batches = 0, Batches Processed = 0, and Failures = 0? So from the looks of that it hasn't even ran? – Ricky Hewitt Aug 5 '13 at 15:48
  • Sounds like it... I've heard that jobs which time out during the start() method can get stuck in queued status. But you say that you have no problems generally with running this scheduled? Maybe try aborting this one and see if the next run behaves. – Doug B Aug 5 '13 at 15:54
  • I just deleted the job from the schedule queue entirely and added it again. I'll update with any progress or lack there of. – Ricky Hewitt Aug 5 '13 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.