+ Start a Discussion
philbophilbo 

Using System.Schedule() to schedule Apex job

Hey,

 

When I use System.Schedule() to schedule an Apex job, I am experiencing some strange behavior:

 

* The job does show up on the 'Scheduled Jobs' page on the org, but its 'Manage' link is missing (the only link beside the job entry is 'Del').

 

* According to the 'Scheduled Jobs' page, the job does run at the scheduled time, but there is no evidence anywhere else in the org that the job actually run.  No debug logs appear and none of the side-effects of the job appear on the org.  I even stubbed out the class' execute() method with a System.assert ( False ) statement, to make it throw out an error email, but that doesn't happen either.  It definitely seems like nothing at all is being executed.

 

When I schedule the job via the UI (Develop -> Apex Classes -> Schedule Apex), it runs fine as expected.

 

Why is this?

 

(and why oh why is the page behind the 'Manage' link read-only??)

 

Thanks

spraetzspraetz

The manage link only shows up if you schedule the job from the UI.  This is because the System.schedule() method allows for more flexible scheduling that somtimes cannot be represented in the scheduler UI.

 

As far as the job not being ran, I'd need more information to diagnose.  Can you schedule a job for a few seconds from now and turn debug monitoring on for your user?  If that doesn't show up, you may want to file a support case.

philbophilbo

Thanks Ryan.  "more flexible" meaning, for example, down-to-the-minute scheduling...  :^}

 

What you suggest to diagnose, is exactly what I did (repeatedly).  I had debug monitoring on, but nothing showed up, and I tried to capture the logs two different ways, both thru the System Log window and Setup->Monitoring->Debug Logs (both of which I have found to be fairly reliable in recent times).This even though the 'Scheduled Jobs' page indicated that the jobs HAD been run.

 

I also tried two brute-force-ish things within the execute() method.  First I tried creating+inserting an Account record with a really bogus name, and looking for it in the database afterward.  Nothing.  Then I did what I described in my first post - having the method simply throw an exception.  Again nothing.  (This last one, I left in there when I used the 'Schedule Apex' UI to schedule the job, and sure enough, an exception email did make it to my inbox.)

 

I think I may have exhausted the avenues available to me.  I'll take your advice and open a support case, pending any other words of wisdom on this thread.

 

 

philbophilbo

Hey,

 

Update : I tried this again today - the exact same thing.  Two differences:

 

  1. The job shows up on the UI (Setup->Admin Setup->Monitoring->Scheduled Jobs) complete with the 'Manage' link.  There was no 'Manage' link last week.  Clicking into the Manage link does work; the resulting page shows a subset of the full schedule information (e.g. the hour but not the minute).

  2. The job actually runs.  It did not run last week.

 

Once again - find a problem, make a little noise (I also opened a support case), wait a couple of days and the problem silently, mysteriously corrects itself.  Quelle surprise.

 

 

Jonathan Vance 5Jonathan Vance 5
I am having almost the same problem. My Manage link is fine, but my Scheduled Jobs appear in the Scheduled Jobs list as having run while I can find no indication of them having run anywhere else, especially not in the Debug Logs, where I would expect to see some details. Anybody got any ideas?
Jonathan Vance 5Jonathan Vance 5
I realized I had somehow been deleted under Monitored Users on the Debug Logs page, so I added myself back and now I see the logs again.