ProfessorFlow
ActionActive

Calculate Is Inside Business Hours

Check whether a given DateTime falls within business hours. Holidays are included in the calculation.

v1.0.0Updated yesterday

Overview

Calculate Is Inside Business Hours is an Apex invocable action that wraps Salesforce's native BusinessHours.isWithin() method and exposes it as a Flow-callable action. Pass in any DateTime and a Business Hours record ID, and the action returns a simple boolean indicating whether that moment falls inside the defined working window.

Holidays configured on the Business Hours record are automatically factored in, so a DateTime that lands on a holiday returns false even if it would otherwise be within normal hours. This makes the action ideal for gating time-sensitive logic in your Flows without writing custom Apex.

When to Use This

  • Route cases or leads differently based on whether they arrive during or after business hours
  • Gate notifications so alerts only fire when support staff are on the clock
  • Build conditional branching in Flows that needs to respect your org's working hours and holidays
  • Validate scheduling logic by confirming a proposed DateTime is within operating hours

When NOT to Use This

  • If you need to calculate a future DateTime by adding time through business hours, use the Add Business Hours action instead
  • For simple "is it a weekday?" checks that don't need Business Hours records, use Flow date formulas
  • If you need to find the next available business hour window, this action only checks a single point in time

User Guide

Getting Started

  1. Deploy the calculateIsInsideBusinessHours Apex class to your Salesforce org using SFDX
  2. In Flow Builder, add an Action element and search for "Calculate if Date is Inside Business Hours"
  3. Pass in the DateTime you want to check and the Business Hours record ID
  4. Use the returned boolean (Is within Business Hours?) in a Decision element to branch your Flow logic

Inputs & Outputs

Input2 attributes
givenDateTimeRequired
DateTime

The DateTime to evaluate against the business hours window

businessHoursIdRequired
Text

The Salesforce record ID of the Business Hours to check against (from Setup > Business Hours)

Output1 attribute
dateInsideBusinessHours
Boolean

True if the given DateTime falls inside the specified business hours; false otherwise

Troubleshooting

Getting unexpected false results: Check whether the DateTime falls on a holiday defined in the Business Hours record. Holidays cause isWithin() to return false even during normally active hours.

Business Hours ID not found: Make sure you're passing a valid Business Hours record ID. Use a Get Records element to query the BusinessHours object, or find the ID in Setup > Business Hours.

Timezone confusion: The BusinessHours.isWithin() method evaluates the DateTime in the context of the Business Hours record's timezone. If your Flow passes a DateTime in a different timezone, the result may seem off. Ensure the DateTime and Business Hours timezone align with your expectations.

Code

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

  • calculateIsInsideBusinessHours.cls — The invocable action with Request/Response inner classes
  • calculateIsInsideBusinessHoursTest.cls — Test class with coverage for valid input, null input, and empty 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