Trigger a workflow to send emails only during after office hours and weekends
|Knowledge Article Number||000214530|
|Description||How to trigger workflow email alert when a record is created during weekends or after office hours?|
|Resolution||To achieve this requirement we will use the following logic in sequence.
1. Create custom field with data type as number. Let us call this field as "Created_Time"
2. Create a workflow rule with field update action, that will update the above field with a number value. Example a record created at 9 PM will update the field as 21
3. Create formula field to compute the day of the week. Let us call this field as "Current_Day"
4. Create another workflow rule with email alert action, that will trigger an email if the lead is created between 7 PM and 9 AM on weekdays and anytime during weekend
Use Case - A company wants an email alert sent out when the lead gets created after office hours and during weekends. Office hours are Monday to Friday 9 AM to 7 PM, Mountain Time
So in this use case, an email alert must be sent when the lead is created between 7 PM and 9 AM and during weekends
Workflow in Step 2
Create a workflow on Lead with Evaluation Criteria: Evaluate the rule when a record is created and rule criteria formula must be “True”.
Add an immediate workflow field update action with below formula
VALUE( MID( TEXT( CreatedDate - tzoffset), 12, 2 ) ) - Tzoffset for MST would be : 0.291666667
Tzoffset is calculated as follows
Using the above mentioned formula a MST 9 PM would end up getting a value of 21
In the workflow field update Check the "Reevaluate workflow after field change"
Use this to update the field created in Step 1
Formula in Step 3
CASE(MOD( TODAY() - DATE(1900, 1, 6), 7), 0, "Saturday", 1, "Sunday", 2,"Monday", 3, "Tuesday", 4, "Wednesday", 5, "Thursday", 6,"Friday","")
This formula takes 6th of Jan 1900 as the reference point and calculates the day of the created date.
Workflow in Step 4
Create another workflow on Lead with email alert as the immediate action
Evaluation criteria: created and any time it’s edited to subsequently meet criteria
Rule criteria formula:
or( CreatedTime__c >= 19 && CreatedTime__c <= 09 , Current_Day__c = "Saturday" , Current_Day__c = "Sunday")
So if the current day is Saturday or Sunday and if the created time is greater than 7 PM and earlier than 9 AM, the email alert will be sent.
The logic works the same but the tzoffset and holidays must be adjusted accordingly