+ Start a Discussion
phanip adminphanip admin 

I have a batch class that batch class should not run Saturdays and Sundays and consider as public holidays(like Diwali) how to achieve this ? Pls give me the solution ?

Hi Every One 

Pls help Me the question 

I have a batch class that batch class should not run Saturdays and Sundays and consider as public holidays(like Diwali) how to achieve this ? 
Pls give me the solution ?
Best Answer chosen by phanip admin
Sergio AlcocerSergio Alcocer
If the customer support holidays matches the ones you want to exclude in your batch, you could set them up in the Holidays object (https://help.salesforce.com/articleView?id=customizesupport_holidays.htm&language=en_US&type=0). If this doesn't apply or you don't want to use it, you could use a Custom Setting to store all Holidays.

In any case, my approach would be to schedule the batch from Monday to Friday (which excludes all weekends by default) and on the start method, check if the running date is a Holiday or not. If it is, return empty list; if its not, proceed as normal.


Marking best answers is good for all people.
  • Other users with same question: will be easier to find the right answer without having to go through all of the conversation
  • Other users that knows the answer: saving time before they realise its already answered properly
  • Author: makes him/her happy

All Answers

Sergio AlcocerSergio Alcocer
If the customer support holidays matches the ones you want to exclude in your batch, you could set them up in the Holidays object (https://help.salesforce.com/articleView?id=customizesupport_holidays.htm&language=en_US&type=0). If this doesn't apply or you don't want to use it, you could use a Custom Setting to store all Holidays.

In any case, my approach would be to schedule the batch from Monday to Friday (which excludes all weekends by default) and on the start method, check if the running date is a Holiday or not. If it is, return empty list; if its not, proceed as normal.


Marking best answers is good for all people.
  • Other users with same question: will be easier to find the right answer without having to go through all of the conversation
  • Other users that knows the answer: saving time before they realise its already answered properly
  • Author: makes him/her happy
This was selected as the best answer
phanip adminphanip admin
Hi Sergio

First of all thank you very much

if you possible provide the code of batch apex with scheduling code also..