Add Business Hours
Add an interval of time from a start DateTime, traversing business hours only. Returns the next business date.
Overview
Add Business Hours is an Apex invocable action that calculates a future DateTime by adding an interval of time while only counting business hours. It wraps Salesforce's native BusinessHours.add() method and exposes it as a Flow-callable action.
This is essential when you need to calculate SLA deadlines, response times, or follow-up dates that respect your organization's business hours configuration.
When to Use This
- Calculate SLA deadlines that skip weekends and after-hours
- Determine the next available business date/time from a given start point
- Build escalation timers that only count working hours
- Schedule follow-up tasks within business hours
When NOT to Use This
- For simple date math that doesn't need business hours awareness, use Flow's built-in date formulas
- If you need to subtract business hours (this action only adds time)
- For complex scheduling with multiple business hour sets per record — you'd need custom logic
User Guide
Getting Started
- Deploy the
addBusinessHoursApex class to your Salesforce org - Add the "Add Business Hours" action to your Flow
- Pass in the start DateTime, Business Hours ID, and interval in milliseconds
- The action returns the calculated next business DateTime
Inputs & Outputs
DateTimeThe starting date and time for the calculation
TextThe ID of the Business Hours record to use (from Setup > Business Hours)
NumberThe amount of time to add, in milliseconds (e.g., 3600000 for 1 hour)
DateTimeThe calculated future DateTime after adding the interval through business hours only
Common Time Conversions
| Duration | Milliseconds |
|---|---|
| 1 hour | 3,600,000 |
| 4 hours | 14,400,000 |
| 8 hours (1 business day) | 28,800,000 |
| 24 hours (3 business days) | 86,400,000 |
Troubleshooting
Result is in wrong timezone: The action converts the result to the running user's local timezone. If the result seems off, check the user's timezone setting in Salesforce.
Business Hours ID not found: Make sure you're passing a valid Business Hours record ID. You can find this in Setup > Business Hours. Use a Get Records element to query the BusinessHours object.
Interval seems wrong: Remember the interval is in milliseconds, not hours or minutes. Multiply hours by 3,600,000.
Code
Source code is available on GitHub. The component consists of two Apex classes in a standard SFDX project structure:
addBusinessHours.cls— The invocable action with Request/Response inner classesaddBusinessHoursTest.cls— Test class with coverage for the default business hours- Metadata XML files configured for API version 66.0
Deploy to your org using SFDX:
sf project deploy start --source-dir force-app
Release History
See the release timeline above for version history.