[SalesForce] Run Apex Scheduler Quarterly

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

Best Answer

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

Related Topic