Getting Started with Process Builder – Part 95 (Need to Auto Add Opportunity Contact Role to an Opportunity? Read on!)

Getting Started with Process Builder – Part 95 (Need to Auto Add Opportunity Contact Role to an Opportunity? Read on!)

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.

Process Builder - 95.1

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.

  1. 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.
    1. 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 FlowProcess Builder - 95.21.jpg
  2. 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.
    1. For example, in the last step, you used an action to create renewed Opportunity. Now you want to refer ID of the renewed Opportunity to create an Opportunity contact role.Process Builder - 95.3.jpg

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. 

Process Builder - 95.4

Winter’20 Update

After Winter’20 release you can trigger a Flow using one of the following ways:

  1. Manually via Button Link or Action
  2. Automatically via Process builder or Apex – We will use this method in the article. 
  3. 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:

    1. Click on Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Flow.
    2. 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:
    3. 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}
    4. We will pass the value to {!VarTAccountId} via the Process Builder. 
    5. 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:Process Builder - 95.5.1.jpg

      1. 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}Process Builder - 95.6.1.jpg

        1. 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. 
        2. 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.
    6. 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:Process Builder - 95.7.jpg
    7. 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:Process Builder - 95.8.1
    8. In the end, Martin’s Flow will look like the following screenshot:Process Builder - 95.9.jpg
    9. Once you’re done, Save the flow and name it Opportunity Contact Rolewith 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:

  1. Click on Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Process Builder
  2. To create a new process from scratch, click on the New Button available on Process Management page. A popup will appear where you have to enter the Name (Use Opportunity Contact Role – PB as a name)API Name and Description as shown in the following screenshot:Process Builder - 95.10
  3. Once you are done, click on the Save button.
  4. 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:Process Builder - 95.11.jpg
  5. Once you are done, click on the Save button.
  6. The next task is to add the Process Criteria. To do this, click on Add CriteriaThen, enter NameType of action and set filter conditions ([Opportunity].AccountId Isnull false and [Opportunity].Account.IsPartner Equals Boolean Trueas shown in the following screenshot:Process Builder - 95.12.jpg
  7. Once you are done, click on the Save button.
  8. 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:Process builder - 95.13
  9. Finally, the Process will look like the following screenshot:Process Builder - 95.14.jpg

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.

  1. Navigate to the Opportunity tab, and create a new opportunity for the Partner account.
  2. 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:

Blog 95 - OUtcome

 

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

Leave a Reply

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