Getting Started with Process Builder – Part 71 (Set Your Productivity on Steroids by Creating Reusable Processes!)

Getting Started with Process Builder – Part 71 (Set Your Productivity on Steroids by Creating Reusable Processes!)

Last Updated on November 12, 2017 by Rakesh Gupta

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.

So, here we go:

1. First of all, create a custom field (Out_of_Business__c) data type Checkbox, on account object.
2. Make sure to add value Not Interested for Rating (drop-down) field on the account.
3. Click on Name | Setup | App Setup | Create | Workflows & Approvals | Process Builder
4.
 To create a new process from scratch, click on the New Button available on Process Management page. A popup will appear where you have to enter the following details:

  • Name: Enter the name of the Process. Enter Update Out of Business on Account as a name.
  • API Name: This will be auto-populated based on the name.
  • Description: Enter a meaningful description.
  • This process starts when: Configure the process to start when a record is created or edited or invoked by another process. In this case, select It’s invoked by another process.

5. After Define Process Properties, the next task is to select the object on which you want to create a process and define Evaluation Criteria. For this, click on Object node to add object and then select the Account object. 

6. The next task is to add Process Criteria. To do this click on Add Criteria, enter NameType of action and set filter conditions as shown in the following screenshot:

The reason for selecting ‘No criteria’ option here is that you can easily control the selection from the master process (Process which will trigger this invocable process).

7. The next step is to add an Immediate action to Process. Click on Add Action (Under Immediate actions), Select the type of action (In our case Update Records), as shown in the following screenshot:

8. Once done, click on the Save button, it will redirect you to Process canvas. Finally, the Process will look like the following screenshot:

Don’t forget to active the Process by clicking on the Activate button.

Create a Master Process to Call an Invocable Process

The next step is to create another process (A record changes) on the Opportunity object; it will fire only when Opportunity Stage is updated to Closed Lost and invoke the process we just created.

Perform the following steps to create a master process to call the invocable process we just created:  

1. Click on Name | Setup | App Setup | Create | Workflows & Approvals | Process Builder
2.
 To create a new process from scratch, click on the New Button available on Process Management page. A popup will appear where you have to enter the following details:

  • Name: Enter the name of the Process. Enter For Lost Opportunities as a name.
  • API Name: This will be auto-populated based on the name.
  • Description: Enter a meaningful description.
  • This process starts when: Configure the process to start when a record is created or edited or invoked by another process. In this case, select A record changes.

3. After Define Process Properties, the next task is to select the object on which you want to create a process and define Evaluation Criteria. For this, click on Object node to add object and then select the Opportunity object.  For the entry criteria, Select when a record is created or edited, as shown in the below screenshot:

4. The next task is to add Process Criteria. To do this click on Add Criteria, enter NameType of action and set filter conditions as shown in the following screenshot:

  •  [Opportunity].AccountId Is null Boolean False
  •  [Opportunity].StageName Equals Picklist Closed Lost

5. The next step is to add an Immediate action to update Out of Business (account custom field) to True. For this, we will use the Processes action available in Process. Click on Add Action (Under Immediate actions), it will open an additional window on the right-hand side of process canvas screen, where you have to enter the following details:

  • Action Type: Select the type of action; in this case, select Processes.
  • Action Name: Enter a name for this action. Enter Launch account invocable process as the Action Name.
  • Process: Select the process that you want to execute. In this case, select Update Out of Business on Account. You can only select active invocable processes.
  • Set Process Variables: Select your Process Variable. In this case, map the SObject variable with Account ID.

    It will look like what is shown in the following screenshot:

6. Once done, click on the Save button, it will redirect you to Process canvas. Finally, the Process will look like the following screenshot:

Don’t forget to active the Process by clicking on the Activate button.

It’s time to test the Flow and Process

Next time, when a user updates the opportunity Stage to Closed Lost, both the processes will fire and update the Account Out_of_business__C to True, as shown in the following screenshot:

–> When you create a process that invokes another process, each one counts toward your process and other applicable limits. DML limits in processes that invoke processes count as one transaction.

Technical Editor and Proofreader: - Munira Majmundar
Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

4 thoughts on “Getting Started with Process Builder – Part 71 (Set Your Productivity on Steroids by Creating Reusable Processes!)

  1. With above don’t you have to create a new “master process” on opportunity if say you want to invoke another process if “Opportunity Owner ” changes – ie you will end up with two master processes on Opportunity – rather than 1 as is “best practice”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.