What makes time and time zone operations very difficult:
- In the Salesforce cloud, all system time field values are recorded in GMT – Greenwich Mean Time.
- The organization’s time zone can be set up in the organization settings.
- The user can have a different time zone than the organization.
- Salesforce will use these settings to display the time to the user on the screen. Similarly, these rules and logic govern what the user sees when they view the timestamp on the records and the transactions.
- Installed packages and additional functionality that run in your Salesforce Org can also have time zone settings. Field service lightning – FSL – is a famous example.
- You may think you had enough. Not so fast. The DST – Daylight Savings Time – makes everything even more complicated.
When you display the time in a screen flow running on an external community page to a guest user, Salesforce does not know the user’s time zone.
Even if Salesforce knew, there is no good way to get the user’s time zone or their current local time within the flow. The behavior can depend on what context – user vs. system – you are running your flow in.
This means you need to do the time zone conversion yourself as the flow builder.
A few months ago, I was on Eric Smith’s blog working on implementing the data-table flow component, and I found an invocable action he wrote that returned the start of the day (midnight) for a particular date. I immediately asked what context the action ran because I built a flow for a Nonprofit before, and I had to jump through hoops to try and calculate the time in the correct time zone to be displayed on the screen.
If this action could give me the correct start of the day in the user time zone, I could calculate a time offset for the system time GMT and convert all system times to the user time zone.
Needless to say, the solution worked, and that is why I am here writing about it. Eric Smith was super kind to post a detailed blog post about this. Please find it here.
Using this method, you can calculate at any point in time what the offset – differential time in hours – is between the user’s time zone and GMT. This means you can use this number to convert all the system times to the user’s time zone before displaying them on the screen.
Enjoy your flow-building journey.
P.S. Originally published on 03/7/2022.
Read the previous issue of the newsletter here.
Read the next issue of the newsletter here.
Subscribe to the weekly educational Salesforce Flow Tips newsletter here.
2 thoughts on “Time and Time Zone Operations in Flow – Salesforce Flow Tips Newsletter”
Pingback: 7 Effective Flow Learning Strategies – Salesforce Flow Tips Newsletter | Salesforce Break
Pingback: 10 Things I Hate About Flows – Salesforce Flow Tips Newsletter | Salesforce Break