ProfessorFlow
ActionActive

Calculate Next Business Date

Starting from a target date, returns the next date when business hours are open. If the target date falls within business hours, it is returned as-is.

v1.0.0Updated yesterday

Overview

Calculate Next Business Date is an Apex invocable action that finds the next date and time when business hours are open, starting from a given DateTime. It wraps Salesforce's native BusinessHours.nextStartDate() method and exposes it as a Flow-callable action.

If the target DateTime already falls within business hours, it is returned unchanged. This makes it ideal for scenarios where you need to verify whether a date is within business hours and, if not, find the earliest moment that is.

When to Use This

  • Verify that a target date falls within business hours before scheduling an action
  • Find the next available business date for case assignment or SLA start times
  • Skip weekends and holidays when scheduling follow-up tasks
  • Ensure automated notifications only fire during business hours

When NOT to Use This

  • If you need to add a duration of business hours to a date, use the Add Business Hours component instead
  • For simple "next business day" logic that doesn't need a configurable Business Hours record, a Flow formula may suffice
  • If you need to check multiple Business Hours records per transaction, consider a custom collection action

User Guide

Getting Started

  1. Deploy the CalculateNextBusinessDate Apex class to your Salesforce org
  2. In Flow Builder, add an Action element and search for "Calculate Next Business Date"
  3. Pass in the target DateTime and a Business Hours record Id
  4. The action returns the next DateTime when business hours are open
  5. Use the returned date to schedule tasks, set SLA start times, or gate notifications

Inputs & Outputs

Input2 attributes
givenDateTimeRequired
DateTime

The target date and time to evaluate against the business hours schedule

businessHoursIdRequired
Text

The Id of the Business Hours record to evaluate against (from Setup > Business Hours)

Output1 attribute
nextAvailableBusinessDate
DateTime

The next DateTime when business hours are open. If the input DateTime is already within business hours, the same value is returned.

Troubleshooting

Output matches the input exactly: This is expected behavior when the input DateTime already falls within business hours. The action only advances to the next open window if the input is outside business hours.

Business Hours Id not found: Ensure you're passing a valid Id from the BusinessHours object. Use a Get Records element to query BusinessHours WHERE IsDefault = true to get the default record, or query by name for a specific schedule.

Result seems to skip expected days: Check your Business Hours configuration in Setup. If holidays are configured on the Business Hours record, those days will be skipped as well.

Code

Source code is available on GitHub. The component consists of two Apex classes in a standard SFDX project structure:

  • CalculateNextBusinessDate.cls — The invocable action with request/response inner classes
  • CalculateNextBusinessDateTest.cls — Test class covering standard, empty, null, and bulk input scenarios
  • 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.

Search

Search components, articles, and tags