You need to sign in to do that
Don't have an account?
Randy Ott
Access BusinessHoursSettings directly through APEX
Is there a way to directly access the BusinessHoursSettings directly through APEX - without going through the REST API? I need to access this object from a trigger but can't call the REST API from a trigger.
I can't find any documentation about a BusinessHoursSettings object; but you can definitely query the BusinessHours object, which will give you the start and end times for business hours for each day of the week. See the docs: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_businesshours.htm
And you can try something like this:
<pre>
SELECT Id, MondayStartTime, MondayEndTime, TuesdayStartTime, TuesdayEndTime, (etc.)
FROM BusinessHours
WHERE IsDefault = true
</pre>
So, if I were trying to meet your requirement, I would use a naming convention. For example: for the state of Massachusetts, I would create a BusinessHours record named "Massachusetts", and an associated Holiday record named "Massachusetts - Patriots Day". Then I could use a query like this:
<pre>
String stateFilter = state + '%';
List<Holiday> stateHolidays = [SELECT Id FROM Holiday WHERE Name LIKE :stateFilter];
</pre>
That's the best I can come up with. I hope it helps!