Skip scheduled jobs on weekends and holidays #inSalesforce
Setup | Business Hours | Set Business Hours and Holidays as in visual or per need
Create Apex Class:
global class BusinessHourAndHolidayMaintenanceClass{
@InvocableMethod(label = 'Verify that the Date/Time is within Business Hours including Holiday')
public static List<Results> execute(List<Requests> requestList) {
List<Results> responseWrapper = new List<Results> ();
BusinessHours objBusinessHours = [SELECT Id FROM BusinessHours WHERE IsDefault = true];
if(objBusinessHours != null) {
for (Requests request: requestList){
Datetime targetDateTime = request.InputDateTimeField;
Boolean isWithinBusinessHours = BusinessHours.isWithin(objBusinessHours.id, targetDateTime);
Results response = new Results();
response.outsideOfBussinessHours = isWithinBusinessHours;
responseWrapper.add(response);
}
}
return responseWrapper;
}
public class Requests {
@InvocableVariable(label = 'Date/Time Field' required = true)
public Datetime InputDateTimeField;
}
public class Results {
@InvocableVariable(label = 'outsideOfBussinessHours' required = true)
public Boolean outsideOfBussinessHours;
}
}
Create a flow
Go to existing scheduled flow and save as with a name
Action Element:
Call the Class's Method
Date/Time field - Flow.CurrentDatetime
Manually Assign Variable - outsideOfBussinessHours - varHoliday(New Resource, varHoliday, boolean, default-false (i/p and o/p checked))
Decision Element:
varHoliday = True
If True then existing Scheduled Flow else not
Comments
Post a Comment