Site icon UnofficialSF

Flow Datetime Methods

Flow Datetime Methods

Created by Carl Vescovi


This Post was most recently updated on: 3/27/21
Current Version: 1.0


At the moment Datetime and Business Hours are not particularly well supported in Salesforce Flows. The intent of this code is to be a gap filler until such time as Salesforce delivers more functionality. The way this code works is simple – Salesforce provides much more support in Apex for Datetime manipulation and Business Hours calcs, so the class included here simply serves to provide access to a subset of those Apex Datetime, Date and Business Hour class methods. 48 in total so there is something there for everyone. While some of these functions are probably possible using formulas, in a lot of cases here you can manipulate the result into different timezones and formats – not something I’d personally want to be doing with formulas if there is a ready built capability to be found on the platform.


Datetime support

The Datetime capabilities available to Salesforce Developers can be found here.

The following subset of capabilities or ‘methods’ provided by Salesforce are enabled in Flow through this simple class. To call Datetime specific methods prefix the method with ‘Datetime.‘. For example, to use the Datetime addDays method use the methodname attribute ‘Datetime.addDays’.

Business Hour support

In addition it made sense to extend this class to also provide five methods for Business Hours calculations.

The Business Hours capabilities enabled are described in more detail here.

To access these methods from the action, prefix the method you want to use with ‘BusinessHours.‘. For example, to use the diff method you’d populate the action attribute ‘methodName’ with ‘BusinessHours.diff’.

Date support

Was on a role by this stage so figured best to expose the Date Class methods as well.

More information on Date Class methods can be found here.

To access the following Date Class methods, prefix the method you want to use with ‘Date.‘. For example, to use the dayOfWeek method you’d populate the action attribute ‘methodName’ with ‘Date.dayOfWeek’.


Using the classes from within Flow

Once installed just reference the DatetimeUtility or DateUtility class from within Flow Builder Action to access Datetime and BusinessHours methods, or DateUtility class from a Flow Action to access the Date methods.

Once selected, you’ll want to configure some attributes. There are 3 to 4 attributes to populate depending on which method you wish to call. If its not intuitive enough let me know and I’ll expand the documentation.

Utility Method attributes

The following attributes can be configured once you’ve created the action using either of the DatetimeUtility or DateUtility Classes

Response attributes

The Utility returns a response that has a number of attributes you can use as you wish


Installation

Production or Developer Version 1.0

Sandbox Version 1.0


Release Notes

3/22/21 – Carl Vescovi – v1.0

Initial Release


Previous Versions


View Source

Source Code

Skip to toolbar