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
Just works the first time like everyone is saying.
LikeLike
Hi Akhil,
I hope this is not off-topic, but could you advise please if this can also work for my case? I was trying to send an email alert using WF rule but the field I created in my custom object was a formula field so it is not firing naturally.
My use case is I need to send email alert to the owner whenever his contract is in Pending/Open/Review status, and the contract’s LastModifiedDate is 30 Days. Basically, I am emailing people whose record has no activity in the last 30 days. Our Last Modified Date field is configured such that it covers both contract record editing and activity such as attachments or notes, so I have no issue with my lastmodifieddate. Do you think I can also use this approach here?
Thanks so much for your kind response. So glad that I found this blog; I thought my problem is somewhat related.
All the best,
Juhn
LikeLike
Hello Juhn,
I think this approach should work in your use-case as long as your LastModifiedDate field is not a custom formula field ?
Thanks & Regards,
Akhil Anil
LikeLike
Hi Akhil As much as I would like this to work, it doesn’t seem to. Only the trigger field updating process works. It doesn’t fire the emails.
For example I had created the record at 1045pm on 10/3/2019 , the trigger field was updated at point of creation from workflow 1. Workflow 2 that sends the email and re-updates the trigger date to Today fires the update and changes the date but doesn’t send the email.
The Time Based workflow monitor showed the scheduled the email to run at 12AM on 12/4? the next day (basically 75 minutes after record creation). The email didn’t run at 12am but then the workflow field update ran at 1209 AM and changed the Today to 10/4/2019 which then set the email workflow to 1200AM on 10/5/2019 in the workflow monitor.
Given the first didn’t email I don’t have an expectation that the one scheduled for 10/5 at 12am will. I ran some other experiments with now and date decimal with the same type of failures
I came to this workflow solution out of frustration with process builder not being able to handle the recurring email. No amount with forcing a record update with time trigger firing updates would rerun the process (like unchecking and rechecking a box for example )The only thing that worked to degree was allowing recursion – which caused 2 emails to fire which is not desirable.
I did see Dan’s answer which talked about making sure the time base trigger references the
LikeLike
Akhil thanks for this info. It really helped a lot.
Originally I was having issues with this solution as time conditions are tricky with what they see as the “relevant” updated fields in the record update. I ended up using a custom formula field that always updates to true and then add that as a time dependent action ( setting that field to NULL which then changes back to true). This is in addition to the Time Trigger reset to “now” time dependent action. The initial logic then looks for either criteria as a condition as a fail safe and keeps re-firing. The core of this is always doing some type of update on the relevant fields in the record so that it stays in the workflow queue. Also what another poster set about referencing the right date field – the trigger date field name in the time dependent action
I should also note that NOW() also works in addition TODAY() if you set the trigger field as a date/time field. You then can get more granular with the time dependent action (e.g. 4 hours) which makes it easier to test. I actually also was able to make this work: Set Workflow 1 actions (the one that kicks off the process by setting the initial trigger date) as the immediate action rather than separate workflow from Workflow 2 Trigger Date time dependent flow. It seemed to work fine. it doesn’t refire the immediate action again. Not sure if it was a fluke?
Learned a lot from working this out. Thanks again Akhil
LikeLiked by 2 people
Hi jonraney, Thanks for your comments on this. Would you be able to share a screen shot on what you did as I am struggling to get this to work. Thanks n advance
LikeLike
Hey halfpennyr, sorry I missed this. I’m uncertain how to post images here in this forum. So I’m using this url from my website resource : https://www.jonraney.com/wp-content/uploads/2019/11/workflow.jpg.
Hopefully it will be approved/retained here once I post.
The basics of my flow are for an Employee onboarding process on a custom “Checklist” object that has several groups working on tasks related to the new employee. When a portion of the tasks are done the person responsible checks off the particular task box. But they are many tasks sections involved, so the overall tasks complete remains undone which is refreshing the record status. So there is a formula/update field that checks if all task are done but if not it checks the main all tasks formula box as incomplete. I keep the “ball in play” essentially by setting that incomplete task to null and having the process reset back to incomplete status. This works in combination with the trigger Now() time based flow. Also as mentioned the time trigger MUST be based on the time trigger field you created. So a. start the process rolling by setting the now trigger on create b. have a process that you can continually reset in the time trigger – for ex. some condition that you can set to false that will reset to true in time based trigger c. Account for all those conditions in your criteria.
Hopefully this makes sense!
LikeLike