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 !