Last Updated on December 5, 2020 by Rakesh Gupta
Opportunity Contact Role has two aspects to it: (1) it represents the role a Contact play on an Opportunity; and, (2) it is a junction object between Opportunity and Contact. As we all know, Opportunity and Contact share a many-to-many relationship. For example, a Contact can play a Decision maker role in one Opportunity; and, an Executive sponsor role in another opportunity.
The challenge arises when one wants to configure automation around the Opportunity object and Contact Roles. For example, let’s say that – (1) whenever someone creates an opportunity for an Account, you want to auto add all contacts as contact roles; or, (2) whenever someone creates an opportunity for an Account, you want to auto add key contacts as contact role for the Opportunity.
How would you handle such a requirement? Well, let us take a business use case and try to understand how one can automate such processes.
Business Use case
Martin Jones is a System Administrator at Gurukul on Cloud (GoC). He is in the process of implementing Opportunity management at GoC. Last week, he received the following request from Pardot marketing team:
- Whenever Opportunities are created for Partner Account, automatically add contacts, with Chief Executive officer in their Title, as a primary contact role on the Opportunities.
Solution for the above business requirement
To solve the requirement, one has to use Lightning Flow with Process Builder. You may be wondering, why are we using Lightning Flow? Why does Rakesh not solve the requirement by using just a Process Builder?
Hmmm, the above question is very interesting and crucial in understanding the capabilities, and limitations, of the Lightning Process Builder. But, before discussing it, let me show you a diagram of a process flow at a high level. Please spend a few minutes to go through the following flow diagram and understand it.
If you look at the diagram you will notice two boxes marked A and B. It is due to the presence of these boxes that we need to use Lightning Flow with Lightning Process Builder.
- As of Winter’20 release, Process Builder doesn’t allow you to save the newly created record ID or record id of updated/find records.
- For example, you can create automation, using Process Builder, to create a new Opportunity when someone marks an existing Opportunity as closed-won. But, if you want to update an existing Opportunity record, that was marked as Closed Won by a Sales rep, with a renewed Opportunity ID, then you cannot do so in Process Builder. This is because, a Process Builder does not allow you to, either create a variable or save an ID in a variable, for later use. In such cases, you must use Lightning Flow
- For example, you can create automation, using Process Builder, to create a new Opportunity when someone marks an existing Opportunity as closed-won. But, if you want to update an existing Opportunity record, that was marked as Closed Won by a Sales rep, with a renewed Opportunity ID, then you cannot do so in Process Builder. This is because, a Process Builder does not allow you to, either create a variable or save an ID in a variable, for later use. In such cases, you must use Lightning Flow
- As of Winter’20 release, Process Builder doesn’t allow you to refer the newly created record or updated/find records in the subsequent actions.
Because we need to refer to an ID later in the process and, because Process Builder neither allows you to create a variable nor save an ID in a variable, we need to use Flow to solve such use cases.
Ah! So now you understand why we need both – Lightning Flow and Lightning Process Builder – to solve the above business requirement! With our renewed understanding of the limitations of Process Builder, let us review the process flow diagram again and focus on the part that we will be solving using Lightning Flow as oppose to Lightning Process.
Winter’20 Update
After Winter’20 release you can trigger a Flow using one of the following ways:
- Manually via Button Link or Action
- Automatically via Process builder or Apex – We will use this method in the article.
- Schedule a Flow (New)
Step 1: Create a Flow to find contact and Insert Contact Role
Perform the instructions below to solve the above business requirement using Lightning Flow and Lightning Process Builder:
-
- Click on Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Flow.
- Now click on the New Flow button; it will open the Lightning Flow Designer for you, then select Autolaunched Flow, as shown in the following screenshot:
- Now take a moment and create few variables in the Lightning Flow, as shown in the following table:
Variable – Name Data Type Formula/Default Value Text {!$GlobalConstant.EmptyString} VarTOpportunityId Text {!$GlobalConstant.EmptyString} - We will pass the value to {!VarTAccountId} via the Process Builder.
- The first action item is to find contact with Title Chief Executive Officer. For this we will use the Get Records element onto the Lightning Flow Designer and configure it – as shown in the following screenshot:
- Manually assign variables (advanced) – This is a new feature introduced in Winter’20 for Lightning Flow. It means, going forward you don’t have to create Record Variable or Record Collection Variable. Now Salesforce will automatically create a Record Collection Variable for you. Like in this case, it creates the Record Collection variable {!Find_contact_with_title_Chief_Executive_Officer}
- What happens to the Flow created before Winter’20 – Any flow created before Winter’20, Salesforce will make them as Manually assign variables (advanced). You don’t have to worry about updating old Flows.
- What happens to the Flow created after Winter’20 – After Winter’20 you have the option to create Record Variable/Record Collection Variable or leave it to Salesforce. Salesforce will automatically create one for you.
- Manually assign variables (advanced) – This is a new feature introduced in Winter’20 for Lightning Flow. It means, going forward you don’t have to create Record Variable or Record Collection Variable. Now Salesforce will automatically create a Record Collection Variable for you. Like in this case, it creates the Record Collection variable {!Find_contact_with_title_Chief_Executive_Officer}
- Now, will use the Decision element to check if the previous Get Records element returns a contact record. Drag and drop a Decision element onto the Lightning Flow Designer and configure it – as shown in the following screenshot:
- we will use the Create Records element to insert a record for Opportunity Contact Role object. Drag and drop a Create Records element onto the Lightning Flow Designer and configure it – as shown in the following screenshot:
- In the end, Martin’s Flow will look like the following screenshot:
- Once you’re done, Save the flow and name it Opportunity Contact Role, with Type: Autolaunced Flow. Do not forget to activate the Flow by clicking on the Activate button.
Step 2: Create a Process to launch a Flow
Our next task is to create a Process Builder on the Opportunity object to start a Flow. To create a Process Builder on the Opportunity object follow the steps below:
- Click on Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder
- 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 Name (Use Opportunity Contact Role – PB as a name), API Name and Description as shown in the following screenshot:
- Once you are done, click on the Save button.
- 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 following screenshot:
- Once you are done, click on the Save button.
- The next task is to add the Process Criteria. To do this, click on Add Criteria. Then, enter Name, Type of action and set filter conditions ([Opportunity].AccountId Isnull false and [Opportunity].Account.IsPartner Equals Boolean True) as shown in the following screenshot:
- Once you are done, click on the Save button.
- The next step is to add an Immediate action to Process. Click on Add Action (Under Immediate actions). Then select the type of action to create (In our case Flows). Use Field Picker to choose the field as shown in the following screenshot:
- 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 Process
From now onwards, if a business user creates an Opportunity for a Partner account, then, the Process Builder will automatically add a contact with Title Cheif Executive Officer as Opportunity Contact Role to it.
- Navigate to the Opportunity tab, and create a new opportunity for the Partner account.
- Once done, click on the Save button. The process will automatically add a contact role with a contact whose title is Cheif Executive Officer, as shown in the following screenshot:
Technical Editor and Proofreader: - Munira Majmundar