Flow: Populate "Related Opportunity" field on Contact

Tools: Process Builder, Flow Builder

Are you trying to update a Contact field with a value from Opportunity?

Perhaps you can't figure out how to populate the “Related Opportunity” field?

Or maybe you need to update a different Contact field when Opportunity Stage changes?

Because of the one-to-many relation between those two objects those kinds of automations can be a real headache. In most cases, it’s impossible to get them to work with just the Process Builder.

Lucky for us, we have an even more powerful automation tool at our disposal - a Lightning Flow.

By utilizing both Process Builder and Flow we can create triggered processes and pass specific values to variables and use them to create sophisticated, multi-step automations.

Today, we are going to use an Autolaunched Flow run from a Process Builder that’s going to update a “Related Opportunity” field on Contact.

We’re going to do this in a couple of steps:

  1. We’ll look up the related Opportunity using a value that “connects” both Contact and Opportunity.
  2. Then we’ll get a specific value from a field on that Opportunity and update a field on Contact.
  3. With the flow ready and activated we’ll create a Process Builder that’s going to run it.

Let’s get started.

Step-by-step guide:

1. Open the Flow Builder.

2. Create a Variable to store the value that will help us identify a related object.

Because we are creating this process to update a “Related Opportunity” field on Contact, we will need to store Account ID, as this is the value that both related Opportunity and Contact share. This Variable will be populated in the Process Builder.

Data Type: TEXT

Available for input CHECKED

creating variable in a flow

3. Create a second Variable to store the value that we’re looking for in the related object.

We are looking for an ID of Opportunity related to Contact, so this variable will be used to store the Related Opportunity’s ID.

Data Type: TEXT

Available for input CHECKED

4. Create Get Records activity and configure it:

a. Specify which object you are looking for:

b. Specify the criteria on which we can identify the related Opportunity. We’re going to use the previously stored value in a variable AccountID, which related Opportunity and Contact share.

Field: AccountId equals Value: AccountId (Variable)

configure get records activity

c. Sort the records if you need to.

sort order in get records activity

d. Pick “Choose fields and assign variables”.

creating get records activity and picking how many records to store

e. Store the value you are looking for in the second Variable. In our case, we’re going to store the Related Opportunity’s ID in there.

Field: ID -> Variable: Related_Opportunity_ID

select variables to store opportunity fields

5. Create Update Records activity and configure it.

a. Specify how to find and update records:

update records - specify conditions

b. Specify which object you want to update.

update records activity - choose object

c. Specify the condition requirements to find the right record. Use the first Variable - AccountID to find the right Contact.

update records activity - filter contact records

d. Set which field to update. For the value use the second Variable - Related_Opportunity_ID.

set field values for the contact records

6. That’s it for the Flow Builder. Save and activate the flow.

7. Open the Process Builder.

8. Start the process on Contact when a record is created or edited.

set field values for the contact records

9. Define criteria for the action. Pick “No criteria - just execute the actions!”.

10. Launch the flow and choose the flow created in the previous step. Set the first flow Variable - AccountID with the Contact’s Account ID. Choose Field Reference Type.

11. Activate the process and test it out!

And that's it.

Now, whenever a contact is created or edited, a related opportunity' ID will populate a field. Great job! You can pat yourself on the back.

But remember - flow building doesn't really end here. You should make sure to review it and, as business processes in your organization evolve, be ready to improve this flow if necessary.

Also, this process can be used on different related objects, so you might be able to improve other automations. Be sure to try it out!

Bart Szkaradek