function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Cloud_DragonCloud_Dragon 

Batch Apex Scheduler

Hi Folks,

I have a scenario where my batch apex class should run every 4th working day of month. Any thoughts how can this be done.

Any help would be greatly appreciated - I am kinda stuck on this for a while .. :(
Best Answer chosen by Cloud_Dragon
ShashForceShashForce
Hi,

Under Setup | Develop | Apex Classes, you can click on Schedule Apex, select the batch apex class you want to schedule, and you can choose to either run it on the 4th day (not exactly working day) of every month. You can also choose to run it on, for example, the 1st Thursdayday of every month or the 3rd Monday of every month. There is no option to select only working days.

You can probably try setting up the day of the month in your code itself, using some login like this.

string day = 4,
if(day is saturday){day=day+2}
if(day is sunday){day=day+1}

Then use this day in the cron syntax that is used in the scheduled apex class. I have not tried it myself, but this looks like the only workaround. Apologies for the lazy syntax, but here is a link you can use for scheduled apex example: http://blog.deadlypenguin.com/blog/2012/05/26/scheduled-actions-in-salesforce-with-apex/

Thanks,
Shashank 

All Answers

ShashForceShashForce
Hi,

Under Setup | Develop | Apex Classes, you can click on Schedule Apex, select the batch apex class you want to schedule, and you can choose to either run it on the 4th day (not exactly working day) of every month. You can also choose to run it on, for example, the 1st Thursdayday of every month or the 3rd Monday of every month. There is no option to select only working days.

You can probably try setting up the day of the month in your code itself, using some login like this.

string day = 4,
if(day is saturday){day=day+2}
if(day is sunday){day=day+1}

Then use this day in the cron syntax that is used in the scheduled apex class. I have not tried it myself, but this looks like the only workaround. Apologies for the lazy syntax, but here is a link you can use for scheduled apex example: http://blog.deadlypenguin.com/blog/2012/05/26/scheduled-actions-in-salesforce-with-apex/

Thanks,
Shashank 
This was selected as the best answer
Cloud_DragonCloud_Dragon
Thank you so much!!!