You need to sign in to do that
Don't have an account?

Help determining if a date is a holiday using Apex
Hello!
So I'm trying to figure out how to tell if the date entered in a date field falls on a holiday in Apex. I've been using the isWithin() method in the BusinessHours object to tell if a date is not within business hours, but the requirement has recently changed to go even further. The reason behind this is because we charge different rates on holidays. For example, Saturday would normally be considered "after hours" rates but if Saturday is Christmas Day, then we need a way to mark that in a checkbox or something so we can bill a holiday rate.
Any help is appreciated. Thank you!
So I'm trying to figure out how to tell if the date entered in a date field falls on a holiday in Apex. I've been using the isWithin() method in the BusinessHours object to tell if a date is not within business hours, but the requirement has recently changed to go even further. The reason behind this is because we charge different rates on holidays. For example, Saturday would normally be considered "after hours" rates but if Saturday is Christmas Day, then we need a way to mark that in a checkbox or something so we can bill a holiday rate.
Any help is appreciated. Thank you!
I have an apex class that does something like this.
It uses the businesshour.add method. Basically, if you add one millisecond to system.now() and it's still the same date, then you know that you are within the business hours (otherwise, that second would kick you into the next day when you re-open). If you don't specify one, or it's not there, it'll default to your org default business hours.
So to use this to find holidays, set up a business hours (org settings) where you're 24/7 but with some holidays. Mine is testing that we ARE open, so based on your question you might want to switch the true/false condition to return true when it IS a holiday.
If it helps, please mark it as best answer
Thanks!