UPDATE: New Tool Available (January 2018)
I’ve developed a new, more robust tool, Mass Action Scheduler, that lets you declaratively schedule Process Builder, Flows, Quick Actions, Email Alerts, Workflow Rules, and Apex to process records from Reports and List Views.
Inspired by Marie Chandra’s idea Ability to schedule when process builder triggers, I developed a declarative way to schedule process builder to run at arbitrary times.
The most common use case for Process Builder is as a workflow tool to do things whenever some record, say an Account or Contact, is created or updated. But what if you had a use case where you wanted to create new records once a month? Or you wanted to call a Flow every day at 10am? How would you schedule that in Process Builder and not make it dependent on some other record like an Account or Contact being created or updated but rather occur on a predictable schedule? Introducing Process Builder Scheduler!
It is true that Process Builder cannot simply be invoked without the context of a record being created or updated. However, we can control the object that a process monitors and when those records get updated.
In this solution, I created a simple custom object Process_Builder_Schedule__c that captures a process’ API name and a cron expression indicating the schedule of when the process should run. When the record is activated by checking the Active__c field, an apex job is scheduled to periodically update that record by incrementing its Times_Triggered__c field +1. When the record is updated on that schedule then Process Builder runs and performs whatever actions you setup. Voila!
The trick is that these arbitrarily run processes don’t need to be contextually aware of a specific Account or Contact record being created or updated, they simply need to run on a predictable schedule. Therefore, as the administrator you create processes to run when records of this Process Builder Schedule object type are updated. In your process part of the criteria you setup checks if the record’s Process_API_Name__c field matches the value you’re looking for, and if so then you perform your actions, else you ignore it.
The unmanaged package comes bundled with an example process named Auto Post to Chatter that shows you how to setup the criteria node in your processes. Please read full instructions, screen shots, and installation links of the unmanaged package on my github repository: https://github.com/DouglasCAyers/sfdc-process-builder-scheduler.
I’m interested to hear your all’s ideas on better ways this can be achieved or other features you’d like to see in such a tool like this.
Enjoy!
This is Awesome Doug. I think now the power of this tool is only limited by a Salesforce Admins’ creativity 🙂
LikeLiked by 2 people
Very nice work Doug. You beat me to this. I was going to do something similar but your solution is FAR more elegant.
Thanks a ton for saving me the time.
LikeLiked by 1 person
Thanks Joey! What were you going to try?
LikeLike
Nice Work! Really good post
LikeLiked by 1 person
Thanks!
LikeLike
I have this kicking off a flow to look up accounts, update them, and create cases for them. It’s awesome!!
LikeLiked by 1 person
Excellent! Thanks for the feedback about how you’re using the scheduler!
LikeLike
Hi Doug,
I tried to install the package from the production URL (https://login.salesforce.com/packaging/installPackage.apexp?p0=04tj0000001ejTg) and this error message appeared:
This app can’t be installed.
There are problems that prevent this package from being installed.
Apex Classes(classes/ProcessBuilderRescheduleInvocable.cls-meta.xml) Missing feature Installing this package requires the following feature and its associated permissions: Apex Classes
I chose “Install for Admins Only”. I am a system administrator.
LikeLiked by 1 person
Hi Brian,
This error usually indicates the edition of the Salesforce instance the code is deploying to doesn’t support Apex. For example, Professional and Group editions have restrictions on what code can be installed into them.
https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/dev_packages_apex_ge_pe.htm
The package link I provided is an unmanaged package and not created from a certified ISV partner.
Verify the edition of the org you’re installing into. If it’s Professional or Group I’m not sure I can help you 😦
Thanks,
Doug
LikeLike
Hi Doug,
We have Professional. Womp womp. This is a big thing we would like to implement a lot of processes around. Hopefully someday there will be a solution. Thank you!
LikeLiked by 1 person
Hi Doug. I have an existing process (lets call this Process 1) that has its own evaluation criteria which I would like to schedule annually. I installed your package in sandbox, and I’m trying to connect Process 1 with your Process_Builder_Schedule__c. However, I’m not understanding how to make this connection with the installed package. Can you please explain?
LikeLiked by 1 person
To better ask my question, how do I add further criteria to the process? My understanding is that we have to add criteria to to the Process_Builder_Schedule__c which does not allow to create criteria related to other objects. Am I misunderstanding something here? Is this only allowing time based criteria? Sorry for so many questions, trying to understand what you have created so I can utilize it the best possible way.
LikeLiked by 1 person
Hi Himu,
This solution simply allows the ability to schedule when a Process Builder will run. As noted in the blog post, there is no way for the scheduler to have context to any specific records like Accounts or Contacts, etc.
When you install this solution to your org it comes with an example Process Builder which simply posts a Chatter message. What you could do if you need actions to occur on specific records is have the launched Process call a Flow. In your Flow you can query for records that meet your desired criteria and take appropriate action.
Another approach would be to use standard Scheduled Actions in your existing Processes that run based on a custom date field. The value might be the start of the year. When the scheduled action runs you simply update the custom date field to be the start of next year (reschedule the process). The update would cause any other processes configured for that object to run and thereby you can do what you need.
Hope that helps!
Doug
LikeLike
Hi Doug,
Really awesome, super-lighting power for admins. 🙂
I have one-question, It is Bulkified ? Can we user process builder for updating Mass records ?
LikeLiked by 1 person
Hi Baba,
Thanks for the feedback, glad you like it!
Yes, Process Builder and Flow are bulk-friendly. Please see this help article for enhancements made in the Winter ’16 release: https://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_forcecom_process_bulkification.htm
Thanks,
Doug
LikeLike
Hi Doug. I tackled this problem from another way. Utilising reports to define, filter and schedule updates.
I have written a draft of a generic apex class that a report schedule can call and then it updates a datetime field on those records which a process builder can notice and invoke a change.
In my opinion this a bit easier for an admin as you can add all sorts of great report filters in.
See it here
https://github.com/dthowell/DeclarativeScheduler
LikeLiked by 1 person
Hi dthowel,
Nice approach. I agree that letting users define criteria in reports is awesome because it’s standard feature and easy to use. I’ve actually begun doing that in some other work projects.
Your project has inspired me to take another look at this and I’ve jotted down my notes for Process Builder Scheduler 2.0.
For your project as you begin to work on unit tests and such, you might find what I’ve done in another project for report notifications helpful. The code is standing on the shoulders of giants like Peter Knolle and Andy Fawcett: https://github.com/DouglasCAyers/sfdc-add-contacts-to-campaign-report-service
Thanks,
Doug
LikeLike
Awesome, just found this.
LikeLiked by 1 person
Thanks for sharing Carlos! Glad you like it.
LikeLiked by 1 person
Hello – How do I create an action in the process builder that I’d like to update a field on all accounts?
LikeLiked by 1 person
Hi Chris,
You will need to launch a Flow from your Process Builder and then in the Flow you can do either a Fast Lookup to query all accounts or a Record Update step to update all accounts that meet your criteria.
Process Builder alone can only update records related to the main record that caused the process to fire. But once your process launches the Flow then Flow can do nearly anything you want.
Doug
LikeLike
This is really helpfull, thanks for sharing this! I was able to create to schedule a test process, next step is to see if this allows us to replace our custom batch query tool.
LikeLiked by 1 person
Thanks Robert for the kind feedback!
LikeLike
I am so excited to have found this. It takes a little bit of the pain away from not being able to be at Dreamforce this week.
LikeLiked by 1 person
Hi Teri,
Glad you like it! Thanks for the positive feedback 🙂
Doug
LikeLike
Hi Doug,
I stumbled across this while looking for a solution to a problem I’m having and was surprised to see that you were the speaker at the Enhanced Notes session I attended at Dreamforce last month. Thank you for everything you do to help us admins.
I am still confused by some of this, specifically steps 2 and 3 in your Github instructions. I need to use your solution on a process that I have already built, let’s call it ‘Create A New Task’. It runs on one of our custom objects, let’s call that ‘Medical Test__c’. Records in this object are created and updated by automated processes that run nightly on an external system (Boomi). My PB process creates a new task when a record is updated by Boomi and meets certain criteria, one of which is ‘Finalized Date’ (the point here being that every night there is a set of these records that is finalized by one Boomi process).
LikeLiked by 1 person
(sorry this got sliced in half, continuing from above)
The problem is that there is another external Boomi process that creates child records in another object when these finalized records meet another set of criteria. This is scheduled to run after the first Boomi process. There is overlap between the two criteria, so some records would be selected by both my SFDC process and this external process. We want this second process to take precedence, so that SFDC doesn’t create tasks on records which have had child records created on them. Yes, ‘Medical Test__c’ has a checkbox that basically asks “Were child records created?”, but that field is updated by the second process. So I can’t make my task creation a Scheduled Action, because SFDC would grab its set of records when they’re updated by the first process and only wait to create the tasks; it wouldn’t go back to look at this checkbox, which would have been checked in the interim.
Bottom line: Process Builder Scheduler seems to be the only way I can make this work declaratively. I know when these Boomi processes run; if I can schedule ‘Create A New Task’ to run at 3am, and exclude all records with “Were child records created?”=TRUE, I’m in like Flynn.
So how do I make ‘Create A New Task’ run with Process Builder Scheduler? Per Step 1 of your Github instructions, I basically cloned a new process I call ‘PB Scheduler’ from your process ‘Process Builder Scheduler’. Within the criteria node for that process, do I simply replace ‘Auto Post to Chatter’ with ‘Create A New Task’? Do I have to recreate my process as an invokable process? Or worse, do I have to recreate it as a Flow? (I really struggle with Flows and would like to avoid this if at all possible.)
Again, thanks for helping to simplify things for us beleaguered admins.
LikeLiked by 1 person
Hi Andrew. I think you might benefit from using a different tool. One I developed work assistance from Doug and some of his code. You define the schedules easily and the inclusion logic is built from reports. So you could set up different reports for your varying criteria. http://gravitylab.nz/declarative-scheduler-tool/
LikeLiked by 1 person
Hi Andrew,
Glad you enjoyed my Dreamforce Session, and thank you for the kind words and compliments!
This Process Builder Scheduler project lets you schedule when the process on the custom object it comes bundled with fires. Like the example in the project to auto post a Chatter message. Where you would fit your custom logic into the example is instead of posting a Chatter message you would launch a Flow. That flow can be as simple as doing a Fast Lookup to find the records you want to operate on then simplying updating those records so that your other processes fire.
Another approach is try out Daniel’s scheduler tool that lets you define a report for the criteria of the records you wanted updated at a specific time.
Doug
LikeLike