Book Image

Salesforce Process Builder Quick Start Guide

By : Rakesh Gupta
Book Image

Salesforce Process Builder Quick Start Guide

By: Rakesh Gupta

Overview of this book

Salesforce Management System is an information system used in CRM to automate business processes, such as sales and marketing. Process Builder is a visual tool created to automate business processes in Salesforce. It enables users with no coding expertise to build complex Salesforce workflows. The book starts with an introduction to Process Builder, focussing on the building blocks of creating Processes. Then you will learn about different applications of Process Builder for developing streamlined solutions. You will learn how to easily automate business processes and tackle complex business scenarios using Processes. The book explains the workings of the Process Builder so that you can create reusable processes. It also explains how you can migrate existing Workflow Rules to Process Builder. By the end of the book, you will have a clear understanding of how to use Flows and Process Builder to optimize code usage.
Table of Contents (12 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Foreword
Contributors
Preface
Index

Creating applications with Process Builder


Before Process Builder was available, knowledge of Apex and Visualforce was required to automate complex business processes in Salesforce. After completing this chapter, you will have a clear idea of how to automate business processes using Process Builder, and will minimize your need for Apex code. Now, we will discuss how to use Process Builder to automate business processes. From now on, we will use Lightning Experience to create or manage processes using Process Builder, and to create or manage Visual Workflows.

Hands on 1 – auto-create a child record

Businesses commonly require the auto-creation of a child record whenever a parent record gets created. For example, as soon as an account gets activated, we need to auto-create an opportunity for that account, and we need to set the opportunity close date to the last date of the current quarter. To satisfy this type of business requirement, a developer normally writes an Apex trigger, but there are a few other ways to achieve it, without writing code:

  • Using Process Builder
  • Using a combination of Flow and Process Builder
  • Using a combination of Flow and an Inline Visualforce page, on the account detail page

We will use Process Builder to solve this business requirement.

Let's consider a business scenario. Suppose that Joe Thompson is working as a system administrator at Universal Containers. He has received a requirement from the management to auto-create a contract as soon as an account gets created in Salesforce, and to auto-populate these values in the new contract:

  • Contract term (months): 12
  • Contract start date: Account created date, + 90 days
  • Status: Draft
  • Auto-relate it with a new account

Creating a process

To solve the preceding business requirement, we will use Process Builder. In the runtime process, we will auto-create a contract record whenever a new account record gets created. To do this, follow these instructions:

  1. In Lightning Experience, click on Setup (gear icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder; click on the New button, and enter the following details:
    • Process Name: Enter the name of the process. Enter Auto create new Contract as the Process Name. It must be within 255 characters.
    • API Name: This will be auto-populated, based on the name. It must be within 77 characters.
    • Description: Write some meaningful text, so that other developers or administrators can easily understand why this process was created.
    • This process starts when: This allows you to select when you want to start your process. The following options are available:
      • A record changes: Select this option if you want to start your process when a record is created or edited.
      • It's invoked by another process: Select this option if you want to invoke your process from another process. This allows you to create an invocable process. An invocable process is a process that starts when another process invokes it. In Chapter 3, Building Efficient and Performance-Optimized Processes, we will discuss a few use cases in detail.

In this case, select A record changes. The fields should appear as follows:

  1. Click on the Save button when you have finished. It will redirect you to the process canvas, which will allow you to create the process by clicking, not code.

Adding an object and evaluation criteria

Once you are done defining the process properties, the next task is to select the object upon which you want to create a process and define the evaluation criteria:

  1. Click on the Add Objectnode, as shown in the following screenshot:
  2. This will open a window on the right-hand side, where you will have to enter the following details:

    • Object: Start typing, and then select theAccountobject.
    • Start the process: For Start the process, select only when a record is created. This means the process will fire only at the time of record creation.
    • Recursion – Allow process to evaluate a record multiple times in a single transaction?: Select this checkbox only when you want the process to evaluate the same record up to five times in a single transaction. It might reexamine the record, because a process, Workflow Rule, or Flow may have updated the record in the same transaction. In this case, leave the box unchecked. The window should appear as shown in the following screenshot:
  1. Once you are done, click on the Save button. Just as in Workflow Rule, once you have saved the panel, it doesn't allow you to change the selected object.

Adding process criteria

After defining the evaluation criteria, the next step is to define the process criteria. This is similar to the rule criteria in Workflow Rule. Once the process criteria are true, the process will execute with the associated actions:

  1. To define the process criteria, click on the Add Criteria node, as shown in the following screenshot:
  1. Now, enter the following details:
    • Criteria Name: Enter a name for the criteria node. Enter Always in Criteria Name.
    • Criteriafor Executing Actions: Select the type of criteria that you want to define. You can select Formula evaluates to true, or Conditions are met (a filter to define the process criteria), or No criteria-just execute the actions! In this case, select No criteria-just execute the actions! This means that the process will fire for every condition. The window should look as follows:
  1. Once you are done, click on the Save button.

Adding an action to a process

Once you are done with the process criteria node, the next step is to add an immediate action to create a contract. For this, we will use the Create a Record action, available in Process Builder. You can add multiple immediate and scheduled actions for a particular criteria node. The only limitation is the maximum number of criteria nodes that you can add in one process, which is 200. Immediate actions are executed as soon as the evaluation criteria are met.

Scheduled actions are executed at a specified time. We will add an immediate action with the following steps:

  1. We need to add one immediate action to auto-create a record. For this, we will use the Create a Record action, available in Process Builder. Click on Add Action, available under IMMEDIATE ACTIONS, as shown in the following screenshot:

  1. Now, enter the following details:

    • Action Type: Select the type of action. In this case, selectCreate a Record.
    • Action Name: Enter Create Contract record in Action Name.
    • Record Type: Select the object that you want to create a record for. Start typing, and then select the Contract object.
    • Set Field Values: Certain fields are required when you create a record. When you select the object that you want to create a record for, Process Builder automatically displays the required fields for that record in each row. In this case, a row for Account ID and Status shows automatically. When setting a value for a given field or a field you have added, the available value types are filtered, based on the field that you have selected. The available value types are:
      • Currency: You can manually enter a currency value.
      • Boolean: This allows you to choose a true or false Boolean value.
      • DateTime or Date: You can manually enter a DateTime or Date value.
      • Formula: You can easily create a formula, using functions and fields.
      • Global Constant: This allows you to choose a global constant to set a value to null or an empty string. For example, choose $GlobalConstant.Null or $GlobalConstant.EmptyString
      • ID: You can manually enter a Salesforce ID.
      • MultiPicklist: This allows you to choose one or more multi-select picklist values.
      • Number: You can manually enter a number value.
      • Picklist: This allows you to choose a picklist value.
      • Reference: This allows you to choose a value, based on a field on the record or on a related record.
      • String: You can manually enter a string value.

To select the fields, you can use field picker. To enter the values, use the text entry field and map the fields according to the following screenshot:

Use the formula to set the Contract Start Date dynamically, based on the preceding requirement; in this case, you should use the account created date + 90 days. Use Function to select DATEVALUE (it returns a date value for a DateTime), use the Field picker to select the Created Date field, use Operator to select +, and then enter 90, as shown in the following screenshot:

The new record'sCreated Byfield is set to the user that started the process by creating or editing a record.

  1. Once you are done, click on the Save button to save the process's immediate action. The process will appear, as shown in the following screenshot:

Activating a process

As soon as you are done with the process creation, the next step is to activate it:

  1. To activate a process, click on the Activate button, available on the button bar, as shown in the following screenshot:
  1. A warning message will appear on the screen. Read it carefully, and then click on the Confirm button, as shown in the following screenshot:
  1. When you click on the Confirm button, it will activate the process.

For activation, a process must have an action added to it. If a process doesn't have an action added to it, the activate button won't be clickable. After the activation of a process, it's impossible to make any changes to it. If you want to do that, you will have to clone the process, and save it as either a New Version or a New Process, which we will discuss later:

From now on, if you create a new account, you will see a contract created for the account by the process you made, as shown in the preceding screenshot.

Deactivating a process

If some active processes are no longer required by the business, you can deactivate them. To deactivate an activated process, open the process and click on the Deactivate button, as shown in the following screenshot:

After deactivation, Salesforce stops using the process to evaluate when an account record is created or edited. After you deactivate a process, any scheduled actions will still be there, in a queue for execution.

Deleting a process version 

If a process version is no longer in use, you can delete it. You can only delete those process versions that are in the Draft, Inactive, or Invalid Draft status. This means that you can't delete an active process. If you want to delete an active process version, you must deactivate it first, and then delete it. If a process version has scheduled actions, then you can't delete it; in such a case, you must wait until those pending actions have been completed or deleted. To delete a process, follow these instructions:

  1. Navigate to Setup (gear icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder.
  2. This will redirect you to the Process Management page. Click on the name of the process whose version you want to delete.
  3. Identify the process version that you want to delete, and click on Delete, as shown in the following screenshot:

If your process has only one version and you delete that version, the whole process will be removed from the Process Management page.

Hands on 2 – auto-update child records

There may be business use cases wherein a customer will want to update child records based on some criteria; for example, auto-updating all related opportunities to Closed Lost, if an account is updated to inactive. To achieve these types of business requirements, you can use an Apex trigger. You can also achieve these types of requirements using the following methods:

  • Process Builder.
  • A combination of Flow and Process Builder.
  • A combination of Flow and the Inline Visualforce page, on the account detail page.

We will use Process Builder to solve these types of problems.

Let's look at a business scenario. Suppose that Alice Atwood is working as a system administrator at Universal Containers. She has received a requirement that once an account gets activated, the account Phone must be synced with the related contact Asst. Phone field. This means that whenever an account Phone field gets updated, the same phone number should be copied to the related contact's Asst. Phone field.

Follow these instructions to achieve the preceding requirement using Process Builder:

  1. First of all, navigate to Setup (gear icon) | Setup | PLATFORM TOOLS | Objects and Fields | Object manager | Fields & Relationships, and make sure that the Active picklist is available in your Salesforce organization. If it's not available, create a custom Picklist field with the name Active, and enter the Yes and No values.
  2. To create a process, navigate to Setup (gear icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder, click on the New button, and enter the following details:

    • Process Name: Enter Update Contacts Asst Phone in Process Name.
    • API Name: This will be auto-populated, based on the name.
    • Description: Write some meaningful text, so that other developers can easily understand why this process was created.
    • This process starts when: Configure the process to start when a record is created or edited. In this case, select A record changes.

The properties window will look as follows:

  1. Once you are done, click on the Save button. It will redirect you to the process canvas, which will allow you to create or modify the process.
  2. After defining the process properties, the next task is to select the object upon which you want to create a process and define the evaluation criteria. For this, click on the Add Object node. It will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Object: Start typing, and then select the Account object.
    • Start the process: For Start the process, select when a record is created or edited. This means that the process will fire every time, irrespective of record creation or update.
    • Recursion - Allow process to evaluate a record multiple times in a single transaction?: Select this checkbox only when you want the process to evaluate the same record up to five times in a single transaction. In this case, leave the box unchecked. The window will appear as shown in the following screenshot:

 

  1. Once you are done, click on the Save button.
  2. After defining the evaluation criteria, the next step is to add the process criteria. Once the process criteria are true, the process will execute the associated actions. To define the process criteria, click on the Add Criteria node. It will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Criteria Name: Enter Update Contacts in Criteria Name.

    • Criteria for Executing Actions: Select the type of criteria that you want to define. You can select either Formula evaluates to true, or Conditions are met (a filter to define the process criteria), or No criteria-just execute the actions! In this case, select Conditions are met.

    • Set Conditions: This field lets you specify which combination of the filter conditions must be true for the process to execute the associated actions. In this case, select Active as Yes. This means that the process will fire only when the account is active.

    • Conditions: In the Conditions section, select All of the conditions are met (AND). This field lets you specify which combination of the filter conditions must be true for the process to execute the associated actions.

    • Under Advanced, select Yes to execute the actions only when the specified changes are made. This means that the actions will be executed only if the record meets the criteria now but the values that the record had immediately before it was saved didn't meet criteria. This means that these actions won't be executed when irrelevant changes are made. For example, if the account status is Active and a user updates the record by adding a Shipping Address, the process won’t execute the associated actions. This setting isn’t available if:

      • Your process starts only when a record is created.

      • Your process starts when a record is created or edited, and the criteria node doesn’t evaluate any criteria.

      • The criteria node evaluates a formula, but the formula doesn’t include a reference to the record that started the process.

      • Your process uses the Is changed operator in a filter condition.

In this case, leave the box unchecked. At the end of the process criteria, a window will appear, as shown in the following screenshot:

  1. Once you are done, click on the Save button.

  2. Once you are done with the process criteria node, the next step is to add an immediate action to update the related contact's Asst. Phone field. For this, we will use the Update Records action, available in Process Builder. Click on Add Action, available under IMMEDIATE ACTIONS. It will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:

    • Action Type: Select the type of action. In this case, select Update Records.

    • Action Name: Enter a name for the action. Enter Update Asst. Phone in Action Name.

    • Record Type: Select the record (or records) that you need to update. Click on the Record type; it will pop up a window, where you will see the following options:

      • Select the Account record that started your process.

      • Select a record related to the Account.

      • These are radio buttons, and only one can be selected to update the child record. In this case, choose Select a record related to the Account. Then, in the Type to filter list, look for the child object, Contacts, as shown in the following screenshot:

    • Criteria for Updating Records: Optionally, you can specify conditions to filter the records you are updating. Select No criteria—just update the records! There are cool use cases around it, which we will discuss in Chapter 3, Building Efficient and Performance-Optimized Processes.

    • Field: Map the Asst. Phone field with the [Account].Phone field. 

Select the Contacts object, and then click on the Choose button. To select the fields, you can use the field picker. To enter the value, use the text entry field. It will appear as follows:

  1. Once you are done, click on the Save button.

  2. The final step is to activate the process. Click on the Activate button, available on the button bar. Finally, the process will appear, as shown in the following screenshot:

From now on, if users try to update the Phone field of an active account, the process will automatically update the related contact's Asst. Phone field with the value available in the account's Phone field, as shown in the following screenshot:

Before testing the process, make sure that you have activated it.

Hands on 3 – cloning a process

Once you have activated a process, it doesn't allow you to make any changes to it. If you want to make any changes to an active process, you have to clone it and save it as either a New Version or a New Process.

Let's look at a business scenario. Suppose that Alice Atwood is working as a system administrator at Universal Containers, and she has created a process (Update_Contacts_Asst_Phone) to update the related contact's Asst. Phone field from the account's Phone field, once an account gets activated and after that related contacts Asst. Phone field must be synced with account Asst. Phone field. She has received another request from the business, saying that they want to add one more condition to the process. The entry criteria are such that the condition will work only for accounts wherein the billing country is the USA.

To meet this business requirement, you will have to add one more condition to the existing process. For this, you will have to modify your process. As the process is already activated, the only possibility is to clone it. To clone a process, follow these instructions:

  1. Click on the Clone button, available on the button bar. It will open a popup for you. Under Save As, select the appropriate options:
  2. From the Process Management page, click on the process that you want to modify. It will redirect you to the process canvas page:
    • Version of current process: This allows you to create a new version of an existing process.
    • A new process: If you want to create a new process, select this option.

In this case, select Version of current process to create a new version of an existing process, as shown in the following screenshot:

  1. Click on theSavebutton when you are done.
  2. Now, you can modify the process as per the preceding business requirement, as follows:

The business requirements will appear, as shown in the preceding screenshot. Once you are done, click on the Activate button to activate the current version of the process. Salesforce automatically deactivates others active versions of the current process, if any exist.

Adding an Apex plugin to your process

Process Builder allows you to call an Apex class that includes methods annotated with @InvocableMethod. You can also pass the required value in Apex class variables:

To do this, select the Apex action in the process. In Chapter 3, Building Efficient and Performance-Optimized Processes, we will discuss a use case wherein the system can auto-delete open cases when an account is out of business, using an Apex class and calling it from Process Builder.

Hands on 4 – posting opportunity details to the Chatter group

Often, a business will want to auto-post the details of records to Chatter groups. This is possible through Apex code, but there is a way to achieve it without code – that is, Process Builder. Process Builder has a specific action for this, called Post to Chatter. You can auto-post the record details to a Chatter group using the following methods:

  • Process Builder
  • A combination of Flow and Process Builder
  • A Flow and an Inline Visualforce page

Let's look at a business scenario. Suppose that Helina Jolly is working as a system administrator at Universal Containers. She has received a requirement to post opportunity details to the Sales Executive Chatter group, whenever an opportunity gets created with an amount greater than $1,000,000.

Follow these instructions to achieve this using Process Builder:

  1. Create a public Chatter group, named Sales Executive.

Note

Go to https://help.salesforce.com/HTViewHelpDoc?id=collab_group_creating.htm&language=en_US to learn how to create a Chatter group.

  1. To create a process, navigate toSetup (gear icon) |Setup|PLATFORM TOOLS|Process Automation|Process Builder, click on theNewbutton, and enter the following details:
    • Name: EnterPost Opportunity Information to Chatter Group
    • API Name: This will be auto-populated, based on the name
    • Description: Write some meaningful text, so that other developers or administrators can easily understand why this process was created
  2. Once you are done, click on the Savebutton. This will redirect you to the process canvas, which will allow you to create or modify the process.
  1. After defining the process properties, the next task is to select the object upon which you want to create a process and define the evaluation criteria. For this, click on the Add Object node. It will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Object: Start typing, and then select theOpportunityobject.
    • Start the process: ForStart the process, selectonly when a record is created. This means that the process will fire only at the time of record creation.
    • Recursion – Allow process to evaluate a record multiple times in a single transaction: Select this checkbox only when you want the process to evaluate the same record up to five times in a single transaction. In this case, leave the box unchecked.
  2. Once you are done, click on the Savebutton.
  3. After defining the evaluation criteria, the next step is to add the process criteria. Once the process criteria are true, the process will execute the associated actions. To define the process criteria, click on the Add Criteria node. It will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Criteria Name: EnterOnly when amount > $1MinCriteria Name.
    • Criteria for Executing Actions: Select the type of criteria that you want to define. You can select eitherFormula evaluates to true, or Conditions are met (a filter to define the process criteria), or No criteria-just execute the actions! In this case, select Conditions are met.
    • Set Conditions: This field lets you specify which combination of the filter conditions must be true for the process to execute the associated actions. In this case, select a Value greater than $1,000,000.
    • Conditions: In theConditionssection, select All of the conditions are met (AND). This field lets you specify which combination of the filter conditions must be true for the process to execute the associated actions.

Note

The dollar sign ($) is not required when entering the amount. What we enter as criteria can be just the raw number – that is, 10,000,000. The system will add the currency for us.

The process criteria will look as follows:

  1. Once you are done, click on the Save button.
  2. Once you are done with the process criteria node, the next step is to add an immediate action to post the opportunity details to the Chatter group. For this, we will use the Post to Chatter action, available in Process Builder. Click on Add Action, available under IMMEDIATE ACTIONS. This will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Action Type: Select the type of action. In this case, selectPost to Chatter.
    • Action Name: EnterPost to Sales Executive Chatter groupinAction Name.
    • Post to: This allows you to select theChatter Group,orUser,orCurrent Record, where you want to post the opportunity details. From the drop-down menu, selectChatter Group. Then, start typing the name of the Chatter group in the textbox, and selectSales Executive.
    • Message: Enter the message that you want to post. You can also use the fields above the textbox to mention a user or group, add a topic, or insert a merge field into the message.

Immediate actions will appear as shown in the following screenshot:

  1. To insert fields, click on Insert Field. To mention a user or Chatter group, use the Mention a user or group textbox. Finally, to add a topic, use the Add topic textbox. Once you are done, click on the Save button.
  1. Once you are done, the final step is to activate the process. Click on the Activatebutton, available on the button bar. Finally, the process will appear, as shown in the following screenshot:

From now on, if users create an opportunity with an amount higher than $1,000,000, the process will auto-post a textpost to the Chatter group Sales Executive, which will look as follows:

You can also achieve this through a combination of Flow and Process Builder. If you use Process Builder, you can only post a textpost, whereas if you use Flow, you can post a linkpost, textpost, and so on. It will also allow you to set CreatedById. For this, use the Record Create element and the FeedItem object.

Note

You can achieve the preceding requirement using the Post to Chatter static action or the FeedItem object, available in Flow and Process Builder. To learn more about this, refer to https://rakeshistom.wordpress.com/2014/06/14/post-opportunity-details-to-a-chatter-group/.

If you have embedded the Flow in a Visualforce page, you will need to use the Inline Visualforce page on the opportunity object in order to achieve it.

Hands on 5 – sending an email to the opportunity owner

Process Builder also allows you to send emails to users; for example, it allows you to send an email alert to the account owner as soon as an opportunity has successfully closed. 

Let's look at a business scenario. Suppose that Helina Jolly is working as a system administrator at Universal Containers. She has created a process (Post Opportunity Information to Chatter Group) to post opportunity details to a Chatter group if the amount is greater than $1,000,000. She receives another requirement, to send an email to the opportunity's account owner five days after its creation.

Follow these instructions to achieve this by using Process Builder:

  1. Process Builder doesn't allow you to create a new email alert,but it allows you to use an existing email alert that you created in the past, for the same object upon which you created a process. First of all, create an email template, Account owner notification, by navigating toSetup (gear icon) | Setup | ADMINISTRATION | Email | Email Templates, as shown in the following screenshot:
  1. The second step is to create an email alert on the Opportunity object by navigating toSetup (gear icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder | Workflow Actions | Email Alerts. Click on theNew Email Alertbutton, and save it with the name Email to Opportunity Owner. It should look as follows:
  1. To add this email alert to the existing process, navigate toSetup (gear icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder. Open thePost Opportunity Information to Chatter Group process that you created to post the opportunity details to the Chatter group. Save it as a New Version,because you can't modify an activated process.
  2. Now, we have to modify the process entry criteria, to make sure that the process will fire only when a new opportunity is related to an account record. To do that, add an entry criterion in your process, as shown in the following screenshot:
  1. To add the scheduledtime, click onSet Schedule,available underSCHEDULED ACTIONS, and Set Time for Action to Executeto five days after the opportunity's created date, as shown in the following screenshot:
  1. Once you are done, click on theSavebutton.
  1. The next step is to add a scheduled action to send an email. For this, we will use the Send an Emailaction, available in Process Builder. To add schedule actions, click onAdd Action,available underSCHEDULED ACTIONS. This will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Action Type: Select the type of action. In this case, selectEmail Alerts.
    • Action Name: EnterEmail to Account Owner.
    • Email Alert: Select the existing email alert. In this case, select the email alert, Email to Account Owner,which you created in step 2.

Scheduled actions will appear, as shown in the following screenshot:

  1. Once you are done, click on theSavebutton.
  1. Once you are done with the process creation, don't forget to activate the process by clicking on the Activatebutton. Finally, the process will appear, as shown in the following screenshot:

Now, this process will perform both of the jobs: posting the opportunity details to a Chatter group, and sending an email to the opportunity's account owner five days after record creation. The email will look as follows:

Note

Flow also allows you to send emails. You have to use the Send Email static action, available inside of Flow. To learn more about this, go to https://rakeshistom.wordpress.com/2014/09/08/reminder-email-to-upload-chatter-profile-photo/.

If you have embedded the Flow in a Visualforce page, you will need to use an Inline Visualforce page on the opportunity object to fulfill the preceding business use case.

Hands on 6 – checking time-dependent actions from Process Builder

To monitor a time-dependent action queue in Process Builder, follow these instructions:

  1. Navigate toSetup (gear icon) | Setup | PLATFORM TOOLS | Process AutomationFlows.
  2. Go to the Paused and Waiting Interviewssection; from there, you can check out the time-dependent action queue in Process Builder, as shown in the following screenshot:
  1. To remove a record from the time-based queue, use theDellink, as shown in the preceding screenshot.

This is because Process Builder uses a Flow Wait element to create a time-dependent action.

Hands on 7 – submitting a record to an Approval Process

Process Builder also allows you to auto-submit a record to an Approval Process. Currently, the user has to manually submit a record for the Approval Process. You can achieve this type of requirement through the following methods:

  • Using Process Builder.
  • Using a combination of Flow (submit for the approval-static action) and Process Builder.
  • Using a combination of Flow and the Inline Visualforce page on the object's detail page.

Let's look at a business scenario. Suppose that Helina Jolly is working as a system administrator at Universal Containers. She has created a process (Post Opportunity Information to Chatter Group) to post opportunity details to a Chatter group, if the amount is greater than $1,000,000, and to send an email to the opportunity's owner. She receives another requirement: to auto-submit new opportunity records to the Approval Process if the amount is greater than $1,000,000. She has already created a one-step Approval Process for this. It will send an approval request to the CEO.

Follow these instructions to achieve this using Process Builder:

  1. If you haven't created an Approval Process yet, create an Approval Process on the opportunity object, set the entry criteria opportunity amount to greater than 1,000,000, and save it with the name, Opportunity amount greater than 1M. Add one step to it, and send the Approval Request to the CEO role. Make sure that you have activated the Approval Process:

Note

If you want to learn how to create an Approval Process, refer to https://help.salesforce.com/HTViewHelpDoc?id=approvals_creating_approval_processes.htm&language=en_US.

The process (Process Builder) will fail at runtime if it allows the initial submitter to manually select the next approver.

  1. To auto-submit records to an Approval Process, you have to use Process Builder. Navigate toSetup (gear icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder. Open thePost Opportunity Information to Chatter Group process that you created to post the opportunity details to the Chatter group. Save it as a New Version,because you can't modify an activated process.
  2. The next step is to add an immediate action to auto-submit a record to the Approval Process. For this, we will use the Submit for Approvalaction, available in Process Builder. Click onAdd Action,available underIMMEDIATE ACTIONS. This will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Action Type: Select the type of action. In this case, selectSubmit for Approval.
    • Action Name: EnterAuto submit record into approvalinAction Name.
    • Object: This will automatically populate from the object upon which you have created the process.
    • Approval Process: You can selectDefault approval process, or, if the object contains more than one Approval Process, you can use theSpecific approval processoption from the drop-down menu. SelectDefault approval process.
    • Submitter: This allows you to choose a user to auto-submit a record to the Approval Process, and it receives all related notifications. In this case, selectCurrent User.
    • Submission Comments: Optionally, you can enter submission comments. They will appear in the approval history for the specified record. EnterAuto submit, in this case.

The immediate actions will look as follows:

  1. Once you are done, click on theSavebutton.
  1. Once you are done with the process creation, don't forget to activate the process by clicking on the Activatebutton. Finally, the process will appear, as shown in the following screenshot:

Note

You can achieve the preceding requirement by using the Submit for Approval static action, available in Flow and Process Builder. To learn more about this, go to https://rakeshistom.wordpress.com/2014/06/27/auto-submit-record-into-approval-process-with-flow/.

It is not possible to submit any related records to the Approval Process using Process Builder.

Hands on 8 – calling a Flow from Process Builder

Process Builder allows you to launch a Flow. Process Builder is another way to auto-launch a Flow. For example, there is a Flow that allows for the removal of followers from closed opportunity records. If you want this Flow to automatically execute whenever the opportunity status gets closed, you should use Process Builder. 

Some Flows don't require any user interaction to start; for example, a Flow of the type Autolaunched Flow. An Autolaunched Flow can be launched without user interaction; from Process Builder or the Apex interview.start method, for example.

Let's look at a business scenario. Suppose that Sara Bareilles, who is working as a system administrator at Universal Containers, has created a Flow to create a new opportunity using the Record Create element, as shown in the following screenshot:

Currently, she is using a custom button on the Account Page layout to call the Flow. She wants to use Process Builder to automatically fire the Flow whenever an account gets created. The VarD90DaysFromToday object is a date variable, and the VarTAccountId and VarTAccountName variables used in the preceding example are nothing but text variables. We will use Process Builder to pass the values in these variables.

Follow these instructions to call a Flow from the process:

  1. Create a Flow, similar to what is shown in the preceding screenshot; save it with the nameCreate an Opportunity. The Type should be Autolaunched Flow. Click on the Close button to close the canvas. Don't forget to activate the Flow:
  1. To create a process, navigate to Setup (gear icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder, click on the New Button, and enter the following details:
    • Name: Enter Auto create an Opportunity in Name.
    • API Name: This will be auto-populated, based on the Name field.
    • Description: Write some meaningful text, so that other developers or administrators can easily understand why this process was created.
  2. Once you are done, click on the Save button. It will redirect you to the process canvas, which will allow you to create the process.
  3. After defining the process properties, the next task is to select the object upon which you want to create a process and define the evaluation criteria. For this, click on the Add Object node. This will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Object: Start typing the name, and then select theAccountobject.
    • Start the process: For Start the process, select only when a record is created. This means that the process will fire only at the time of record creation.
    • Recursion:Allow process to evaluate a record multiple times in a single transaction?: Select this checkbox only when you want the process to evaluate the same record up to five times in a single transaction. In this case, leave the box unchecked.
  1. Once you are done, click on the Save button.
  2. After defining the evaluation criteria, the next step is to add the process criteria. To define the process criteria, click on the Add Criteria node. This will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Criteria Name: EnterAlwaysas the criteria name.
    • Criteria for Executing Actions: Select the type of criteria that you want to define. You can select eitherFormula evaluates to true, or Conditions are met (a filter to define the process criteria), or No criteria-just execute the actions! In this case, selectNo criteria-just execute the actions! This means that the process will fire in every condition.
  3. Click on the Savebutton.
  4. Once you are done with the process criteria node, the next step is to add an immediate action to launch a Flow. For this, we will use the Flows action, available in Process Builder. Click on Add Action, available under IMMEDIATE ACTIONS. This will open an additional window on the right-hand side of the process canvas screen, where you will have to enter the following details:
    • Action Type: Select the type of action. In this case, selectFlows.
    • Action Name: Enter Auto create new Opportunity in Action Name.
    • Flow: Select the Flow that you want to execute. In this case, select the Create an Opportunity Flow.
    • Set Flow Variables: Use this to pass the value in your Flow variables. For the current use case, map the VarD90DaysFromToday variable with the formula TODAY() + 90, the VarTAccountId variable with [Account].Id, and the VarTAccountName variable with [Account].Name.

The immediate actions will look as follows:

  1. To assign the value to multiple variables, click on the Add Rowlink. Once you are done, click on theSavebutton.
  2. The final step is to activate the process. Click on the Activatebutton, available on the button bar. Finally, the process will appear, as shown in the following screenshot:

From now on, if an account gets created, Flow will automatically be executed by Process Builder, and a new opportunity will be created.