This is one of the most common requirements I have seen with many of the customers and one of the most widely asked questions in the Salesforce success community. So I hope this post will help them to take this example as a reference and set up something similar.
Use Case : ABC Company has a custom object called Survey and a Status field which can have only three values i.e. “New”, “Pending” and “Completed”. They have a requirement wherein once the status of the record in Survey is set to “Pending”, an email should be sent to the Owner of the record every day until the Status of the record is set to either “New” or “Completed”.
Implementation : Most people will resort to an apex batch job which will be scheduled to run everyday and check the status of the record and send out an email. However, why to go with apex customization when this can be easily achieved using Workflow rules ? So, let’s get Started.
We will basically need two workflow rules to set up recurring workflow rules. The first workflow will just have the criteria to check whether the Status is set to “Pending” and will be like below.
Workflow Rule 1
So, the field update for this workflow will be tricky, such that the field update action of this workflow should trigger another workflow which will then trigger in a recurring form. To do that we will need to create a custom Date field in the Survey object. Let’s call it “Trigger Date”. So what we would essentially do is that set the Trigger Date value to TODAY() in the field update action for this workflow.
Workflow Rule 2 Field update Action (Immediate Action)
Note that you need to check the “Re-evaluate workflow Rules after Field Change” checkbox, so that we can allow this field update to trigger another workflow which we will setup next.
The second workflow will have the criteria to check whether the Status is equal to “Pending” and additionally also check whether the Trigger Date value is equal to TODAY (the date on which the rule is fired). This means that this second workflow will get immediately fired on the same day, when the Status was set to “Pending”. Our second workflow will look like below.
Workflow Rule 2
Now, we need to set the Field update of this Workflow in such a way, that it will trigger this workflow again. We will have two Workflow actions for this second workflow. The first one is to send an email alert to the Owner of the record which is pretty simple to setup and so I will not dive into the details of this action. The second workflow action is again the same field update that we used for the first workflow. However, this will be a time-triggered action in this workflow wherein the field update action will fire one day after the Trigger Date value.
Workflow Rule 2 Field Update Action (Time-triggered)
So the immediate and time-triggered actions for your second workflow will look like below.
Overview of Workflow Rule 2 Actions
Just Activate both your workflows and you will see the magic happen !
Now, let see how this works end-to-end.
- A user comes in and sets the status of the Survey record to “Pending” on 1st Jan 2016
- This will fire the first workflow and update the Trigger Date field to 1st Jan 2016
- The update to the trigger Date field will fire the second workflow since the criteria for the second workflow is now satisfied.
- The second workflow will immediately send an email alert to the owner and additionally queue the field update action to be triggered on 2nd Jan 2016.
- The queued field update to Trigger Date is fired on 2nd Jan 2016, thus again triggering the second workflow and queuing the field update action to fire on 3rd Jan 2016.
- This will keep on happening until the Status is set to “Completed” and the second workflow’s criteria will no longer be satisfied and the workflow will stop working.
Happy using workflows !
This is pure Gold ! Thanks for sharing !
LikeLiked by 1 person
Hi Sandeep,
I’m having difficulty with this. If I send you some screenshots would you be able to help me figure out the issue with my workflows?
LikeLike
The 2nd workflow time trigger fired but it did not send an email out. I see its scheduled another update after a day too.
LikeLike
Neel,
did you make it work?
Let me know.I am also trying to use it.
Krishna.
LikeLike
Hey Neel and Krishna,
If you see the action in the scheduled actions, the workflow has definitely fired. The only reason I can think for why the emails weren’t sent is due to an issue with email deliver-ability in your Salesforce org. You might want to test it using the below link
https://help.salesforce.com/articleView?id=security_test_email_delivery.htm&type=0
LikeLike
Akhil,
Thanks for your reply.
For the first time, immediate action email I am getting.
But after a day, when it is queued up and getting executed, it is updating the trigger date field but not sending email.
Thanks,
Krishna.
LikeLike
Also, next time execution not queued up in the Time-Based Workflow queue.
Only first iteration is queued. Somehow criteria is not matching for the successive iterations.
LikeLike
Test Deliverability is good.
LikeLike
Hi Akhil,
First time it is executed, second time onwards it is not executed. can you please tell me what is the problem.
Thanks,
Venkat
LikeLike
Hi Krishna & Neel,
is it working for u? can you please help me i am also faced same problem.
Thanks,
Venkat
LikeLike
Same problem I am facing workflow is working but email alert is not working
LikeLike
Hi Manasa,
If you see the actions scheduled in the queue, then the issue is definitely not to do with the workflow configuration. Instead it is more related to email deliverability set in your organization. Double check and test the email deliverability settings of your org.
LikeLike
I’m having the same issue. I’m not trying to create a task instead of sending an email, so I know that’s not the issue.
LikeLike
its just run only once,
LikeLike
Please ensure that you guys have checked the “Re-evaluate workflow rules after field change” checkbox in the workflow configuration. I can’t think of any other reason why this wouldn’t work 😦
LikeLike
I initially had the same problem described by Venkat. Please make sure that your Workflow Time Trigger is set to “1 Day after [DATE FIELD NAME]”, NOT “1 Day after Rule Trigger Date”. This should fix the issue.
LikeLiked by 1 person
Hi,
I used this strategy to schedule recurring email alerts but somehow it is not working as expected. It only sends an email for the first time. I also tried to make changes based on above comments (to time trigger based on date field) but that didn’t work as well. Am I missing anything? Did this work for any of you?
Thank you.
LikeLike