Process Builder is one of the most used declarative tools to automate business processes in Salesforce. Most of us usually create a new process for each requirement. That not only is not a best practice but, for the long run, it is highly unproductive and unsustainable approach to managing process development. Furthermore, you run the risk of hitting governor limit if you create multiple processes on one object. Therefore, my suggestion is to create a maximum of two processes on each object (First will fire only when a record gets created, second will execute when the record gets updated) and use Visual Workflow to manage your complex logic.
After Winter’17 release it is possible to invoke a process (invocable processes) from another process. With invocable processes, you can reuse sections of your processes. Build one invocable process, call it from multiple processes or from multiple action groups in the same process. By using this method – of reusing a process – you can save time, keep governor’s limit at arm’s length and, boost your productivity!
You can invoke processes with objects that share at least one unique ID. For example, in the Account and Opportunity objects, the AccountId field is unique to Account and also used by Opportunity. You can create an invocable process that updates an Account record. Then you can invoke it from:
- A process that updates an Account record
- A process that updates an Opportunity record
When you create a process, select, It is invoked by another process, option to make sure the process starts when another process invokes it.
Business Use Case
Pamela Kline is working as a System Administrator at Universal Containers. She has received a requirement to update Account custom field, Out of Business, to True if an Opportunity Stage is updated to Closed Lost.
There are various ways, as listed, in which you can solve the preceding business requirement:
- With one Process Builder on opportunity object
- Process Builder with Visual Workflow
- Visual Workflow with Inline Visualforce Page
- Apex Trigger
As of now, the very first solution looks good. After few weeks, however, Pamela received another similar requirement – to update the Account custom field, Out of Business, to True if Account Rating is Not Interested. Oh, no! Not again!
Now she has to re-write the same logic by creating a Process on Account object; this is tedious and time-consuming, to say the least. Because, as you can see, in both the requirements, we are updating Account custom field, Out of Business, to True. How about reusing the existing logic with Account Process? Let us do it!
Solution for the above business requirement
To solve the preceding business requirement (Update Account custom field, Out of Business, to True if an Opportunity is updated to Closed Lost), we will use the concept of invocable process. We have to create two processes for this, as follows:
- The first process (It is invoked by another process) is placed on the Account object to update custom field, Out of Business, to True
- Another process (A record changes) is placed on the Opportunity object, and it will fire only when an Opportunity Stage is updated to Closed Lost.
The benefit of using this approach is that if you get a requirement in the future – to update the Account custom field, Out of Business, to True if Account Rating is Not Interested – then, you call this process from your Account process without adding another Record Update on Account process.