Wednesday, August 17, 2016

Salesforce: Working with Minute, Hour, Day in Workflow, Validation Rule and Formula Field

Use Case: based on some criteria, Event Reminder must be set to 30 minutes prior Event Start date time.

Use Workflow with Field Update or Process Builder, but the logic should be the same. In this case, I'll use Workflow with Field Update for simplicity.

1. Create Workflow Rule and determine the business logic when Field Update action should trigger.

2. Create Field Update action with following formula: ActivityDateTime - 0.020833

- ActivityDateTime = Event Start
- 0.020833 come from 0.5 / 24, where 0.5 = 30 minutes

Notes: when we use a number in Workflow or Formula or Validation Rule for Date or Date/Time field, it is for 1 day count. So for 2 hours, it would be 2/24 = 0.083333

So, when you try to calculate fields of date (date/time), example: NOW() - CreatedDate, this will produce number in days, example: 32.50 meaning 32 days 12 hours.

ReferenceDate/Time Calculations in Formula Fields, Workflow Field Updates and Validation Rules