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
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:
- 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:
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:
- Click on the
Add Object
node, as shown in the following screenshot: 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 theAccount
object.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:
- 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.
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:
- To define the process criteria, click on the
Add Criteria
node, as shown in the following screenshot:
- Now, enter the following details:
Criteria Name
: Enter a name for the criteria node. Enter Always
in Criteria Name
.Criteria
for 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:
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:
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:
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 By
field is set to the user that started the process by creating or editing a record.
- 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:
As soon as you are done with the process creation, the next step is to activate it:
- To activate a process, click on the
Activate
button, available on the button bar, as shown in the following screenshot:
- A warning message will appear on the screen. Read it carefully, and then click on the
Confirm
button, as shown in the following screenshot:
- 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.
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:
- Navigate to
Setup
(gear icon) | Setup
| PLATFORM TOOLS
| Process Automation
| Process Builder
. - This will redirect you to the
Process Management
page. Click on the name of the process whose version you want to delete. - 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:
- 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. 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:
- 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. - 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:
- Once you are done, click on the
Save
button. - 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:
Once you are done, click on the Save
button.
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:
Once you are done, click on the Save
button.
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:
- Click on the
Clone
button, available on the button bar. It will open a popup for you. Under Save As
, select the appropriate options: - 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:
- Click on the
Save
button when you are done. - 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:
Create a public Chatter group, named Sales Executive
.
- To create a process, navigate to
Setup
(gear icon) |Setup
|PLATFORM TOOLS
|Process Automation
|Process Builder
, click on theNew
button, and enter the following details:Name
: EnterPost Opportunity Information to Chatter Group
API Name
: This will be auto-populated, based on the nameDescription
: Write some meaningful text, so that other developers or administrators can easily understand why this process was created
- Once you are done, click on the
Save
button. This will redirect you to the process canvas, which will allow you to create or modify the process.
- 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 theOpportunity
object.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.
- Once you are done, click on the
Save
button. - 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 > $1M
inCriteria 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 theConditions
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.
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:
- Once you are done, click on the
Save
button. - 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 group
inAction 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:
- 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.
- Once you are done, 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 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.
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:
- 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:
- 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 Alert
button, and save it with the name Email to Opportunity Owner
. It should look as follows:
- To add this email alert to the existing process, navigate to
Setup
(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. - 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:
- To add the scheduledtime, click on
Set Schedule,
available underSCHEDULED ACTIONS
, and Set Time for Action to Execute
to five days after the opportunity's created date, as shown in the following screenshot:
- Once you are done, click on the
Save
button.
- 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 on
Add 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, select
Email Alerts
. - Action Name: Enter
Email 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:
- Once you are done, click on the
Save
button.
- Once you are done with the process creation, don't forget to activate the process by clicking on the
Activate
button. 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:
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:
- Navigate to
Setup
(gear icon) | Setup
| PLATFORM TOOLS
| Process Automation
| Flows
. - Go to the
Paused and Waiting Interviews
section; from there, you can check out the time-dependent action queue in Process Builder, as shown in the following screenshot:
- To remove a record from the time-based queue, use the
Del
link, 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:
- 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:
The process (Process Builder) will fail at runtime if it allows the initial submitter to manually select the next approver.
- To auto-submit records to an Approval Process, you have to use Process Builder. Navigate to
Setup
(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. - 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 Approval
action, 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 approval
inAction 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 process
option 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:
- Once you are done, click on the
Save
button.
- Once you are done with the process creation, don't forget to activate the process by clicking on the
Activate
button. Finally, the process will appear, as shown in the following screenshot:
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:
- Create a Flow, similar to what is shown in the preceding screenshot; save it with the name
Create an Opportunity
. The Type
should be Autolaunched Flow
. Click on the Close
button to close the canvas. Don't forget to activate the Flow:
- 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.
- 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. - 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 theAccount
object.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.
- Once you are done, click on the
Save
button. - 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
: EnterAlways
as 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.
- Click on the
Save
button. - Once you are done with the
pr
ocess 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:
- To assign the value to multiple variables, click on the
Add Row
link. Once you are done, click on theSave
button. - 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 an account gets created, Flow will automatically be executed by Process Builder, and a new opportunity will be created.