• Matt McGraw
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi guys, i have a most peculiar behavior with Salesforce scheduler that i've never seen before
So i wrote a little code whose job is just to queue itself every minute to do some work
SomeClass m = new SomeClass();
datetime nextMinuteRun = datetime.now().addMinutes(1);

string sch = '0 '+ string.valueof(nextMinuteRun.minute()) + ' ' + 
string.valueof(nextMinuteRun.hour()) + ' ' + 
string.valueof(nextMinuteRun.day())
+ ' ' + string.valueof(nextMinuteRun.month()) + ' ? ' 
+ string.valueof(nextMinuteRun.year());
            
system.schedule('Keep Running ', sch, m);
This system works fine and keeps rescheduling itself every minute
.. most of the time that is because once in a while, the schedule will fail with the exception in the title and i'd have to restart the scheduler manually again.

Now my guess is that there are times when the system was scheduling itself at say 11:59 : 59
and that gives the next runtime schedule of 12:00 : 00 (a 1 second difference)
but during the process... by the time Salesforce reached the line to schedule the systtem, it was already at 12:00:00, and this causes the failure.

Now, what i am curious is... can Salesforce actually take THAT LONG before it processed the schedule line?
1 second sounds like a short time, but in computer processing that ought to be a long time... especially since this is a line by line code processing that normally would take a fraction of a second.