3

I need to run an apex scheduler for the first day of every current quarter to calculate the revenue for the past quarter. I've already written the batches, however I need to schedule it to run on the first day of the new quarter to get the previous quarter. I wonder if the below expression is correct

public static String Quarter_EXP = '0 0 5 1 1/4 ?'

Thanks

3

The chron string you have works to run on the first of the month, every 3 months. The catch is, it starts on the first of the month, 3 months from when you schedule it. So if you ran that in January, it would start on April 1. I just tried to run it now, in February, and the first run is scheduled for May 1.

You can adjust the chron string to specify the exact months that represent your quarter starts, for example, if your quarters are jan 1 - March 31st, and so on, then you could use

'0 0 5 1 JAN,APR,JUL,OCT ?'

This will run at 5:00am in the first of January, April, July, and October. It will schedule it correctly regardless of when you schedule it

3
  • thank you so much I wonder how can you test it ? many thanks – xiarnousx Feb 4 '15 at 14:47
  • No worries, glad to help :) – Chris Duncombe Feb 4 '15 at 14:47
  • I think when you test a scheduled job, it runs immediately. Of course, when you start it for real, you'll need to check the scheduled jobs to see that it's on the schedule. – Jagular Feb 4 '15 at 15:57

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.