• sansmusic
  • NEWBIE
  • 10 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hey everyone, I've got this Apex class that I swear should work:

 

Global class Page1TaskReadyTriggerDate implements Schedulable {
  global void execute (Schedulablecontext SC){
    
    Page1Task__c[] tasksToUpdate = new Page1Task__c[]{};
    
  date myDate = system.today();
  
  Page1Task__c[] readyTasks = ([SELECT ID, Status__c FROM Page1Task__c 
                WHERE Ready_Trigger_Date__c != NULL
                AND Ready_Trigger_Date__c <= :myDate
                AND Status__c = '1) Not Started']);
          
  for (Page1Task__c rt : readyTasks){
    if (rt.Status__c != null){
    rt.Status__c = '2) Ready';
    tasksToUpdate.add(rt);      
    }
  }
  
  
  update tasksToUpdate;
  
  }
}

 

When I use the baked-in apex scheduler in Salesforce, it will run on the day I set it - but fails on subsequent days. For instance, I set it to run each day at 6am. It will run that day at 6am and set all of my fields accordingly. It fails on subsequent days. Is there something I'm missing or should this be rewritten?

 

Edit: It actually only runs the day the class was generated. It's not getting the system date on subsequent days, Creating a second scheduled apex job results in nothing, but rebuilding the class and scheduling works fine.

  • August 06, 2012
  • Like
  • 1