Last Updated on April 16, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
How do you automatically add an Opportunity Contact Role to an Opportunity?
Objectives:
After reading this blog, you’ll be able to:
- Understand opportunity contact role
- Avoid hard code of Id using the get records element
- Use decision element to check record values
- Auto-create a record using Salesforce Flow
Business Use case
Corey Eridon is working as 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 the 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.
What is an Opportunity Contact Role?
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.
Automation Champion Approach (I-do):
To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario.
Before diving further, let me also show you a diagram of the Flow at a high level. Please spend a few minutes going through the following Flow diagram and understand it. Let’s begin building this automation process.
Guided Practice (We-do):
There are 6 steps to solve Corey’s business requirement using After-Save Record-Triggered Flow. We must:
- Define Flow properties for record-triggered flow
- Create a formula to determine whether the opportunity is created or updated
- Add a decision element to check if the opportunity’s account is a partner account
- Add a get records element to find the contact with the title chief executive officer on account
- Add a decision element to check if contact was found or not
- Add a create records element to associate a contact to an opportunity as a primary contact role
Step 1: Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flow option, click on Create and configure the flow as follows:
- Object: Opportunity
- Trigger the Flow When: A record is created or updated
- Set Entry Criteria
- Condition Requirements: None
- Optimize the Flow For Action and Related Records
- Click Done.
Step 2: Formula to Determine Whether the Opportunity is Created or Updated
- Under Toolbox, select Manager, then click New Resource to determine whether the record is created or updated.
- Input the following information:
- Resource Type: Formula
- API Name: forB_IsNew
- Data Type: Boolean
- Formula: IsNew()
- Click Done.
Step 3: Using Decision Element to Check if the Opportunity’s Account is a Partner Account
Now we will use the Decision element to check if the opportunity’s account is a partner account.
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.AccountId}
- Operator: In Null
- Value: {!$GlobalConstant.False}
- Click Add Condition
- Row 2:
- Resource: {!$Record.Account.IsPartner}
- Operator: Equals
- Value: {!$GlobalConstant.True}
- Click Add Condition
- Row 3:
- Resource: {!forB_IsNew}
- Operator: Equals
- Value: {!$GlobalConstant.True}
- Row 1:
- When to Execute Outcome: If the condition requirements are met
- Click Done.
Step 4: Adding a Get Record Element to Find a Contact with Title Chief Executive Officer
The next step is to use the Get Records element to find contact with Title Chief Executive Officer.
- On Flow Designer, below the Partner Account node, click on the +icon and select the Get Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Contact object from the dropdown list.
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: Title
- Operator: Equals
- Value: Chief Executive Officer
- Click Add Condition
- Row 2:
- Field: AccountId
- Operator: Equals
- Value: {!$Record.AccountId}
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to Automatically store all fields.
- Click Done.
Step 5: Using Decision Element to Check If Contact was Found or Not
Now, will use the Decision element to check if the previous Get Records element returns a contact record.
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!Get_Contact}
- Operator: Is Null
- Value: {!$GlobalConstant.False}
- Row 1:
- When to Execute Outcome: If the condition requirements are met.
- Click Done.
Step 6: Add Action – Create a Record
The next step is to create a record for the Opportunity Contact Role object, for this, we will use the Create Records element.
- On Flow Designer, below the Yes node, click on the +icon and select the Create Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- Input the following information:
- Enter Label the API Name will auto-populate.
- How Many Records to Create: One
- How to Set the Record Fields: Use separate resources, and literal values
- Object: Opportunity Contact Role
- Set Field Values for the Opportunity Contact Role
- Row 1:
- Field: ContactId
- Value: {!$Get_Contact.Id}
- Click Add Field
- Row 2:
- Field: OpportunityId
- Value: {!$Record.Id}
- Click Add Field
- Row 3:
- Field: IsPrimary
- Value: {!$GlobalConstant.True}
- Click Done.
In the end, Corey’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 55
- Interview Label: Auto Add Opportunity Contact Role {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
From now onwards, if a business user creates an Opportunity for a Partner account, then, the Record-triggered flow 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:
Formative Assessment:
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.
One thought on “Need to Auto Add Opportunity Contact Role to an Opportunity? Read on!”