There are two common requests I often get related to Opportunity Contact Roles, both now solved easily with clicks instead of code thanks to Flow and Process Builder!
- Automatically create an Opportunity Contact Role record based on a lookup field on the Opportunity
- Automatically populate a lookup field on the Opportunity with the Contact who is the Opportunity’s Primary contact role
Note: be careful with active Processes when doing bulk data uploads – it’s not bulk-ready and even these simple updates can cause you to hit limits. Update as of Winter ’16 release: Process Builder is now bulkified!
Use Case 1: Automatically create an Opportunity Contact Role record based on a lookup field on the Opportunity
In the nonprofit world, gifts often have Solicitors – other contacts who get soft credit (Opportunity Contact Role) records on gifts (Opportunities) from other donors. It is much easier, with less clicks, to populate a lookup field directly on the Opportunity than it is to create the Opportunity and then add the Contact Role afterwards.
Start with a custom field on Opportunity for the Solicitor. This is just a standard Lookup relationship field to contact:
With your new Flow and Process, when you save the record an Opportunity Contact Role is automatically created for the Solicitor!
If you’ve never touched Visual Workflow, get an overview of how it works here.
This Flow is simply two variables you create and then one element.
Create a variable record for the Opportunity ID:
Now create a variable for the Solicitor’s Contact ID:
I set them both for Input and Output, but Input Only is fine too.
Now you just need to create a single Record Create element to make the Contact Role record.
You’re just populating the Contact ID and Opportunity ID needed in the Contact Role record with the variables you created.
Save and Activate your flow (don’t forget to mark the element as the starting point!) and now you can make the Process that will send the IDs to the Flow and make it happen.
If you need to learn more about Lightning Process Builder, start here.
Here’s your final result:
You’ll want it to fire on Opportunity when a record is created or edited:
I sometimes use formulas for criteria, sometimes I’ll use the drop downs. If I get an error message that a record didn’t create because it failed to activate a Flow, often switching to a formula solves the problem. That is what happened in this case, but as you see in the other example below the criteria is using the filter conditions and it seems to be working just fine. Go with what works.
Now your action is to launch the Flow you just created, and you can pass through the necessary IDs to the variables!
Activate the Process and you’re good to go.
Use Case 2: Automatically populate a lookup field on the Opportunity with the Contact who is the Opportunity’s Primary contact role
This is a common request from nonprofits. An admin wants to create a workflow rule email and send it to the contact who made the donation… except there’s no easy way to pull the contact from the Opportunity Contact Role record. If only that Contact was a Lookup field on the Opportunity, it would be easy. But it’s a pain to keep that data updated for every Opportunity. Too many extra clicks.
With Process Builder and Flow, you can have the Contact Role record that automatically gets created when you start a gift from a contact (such as with Nonprofit Starter Pack):
… automatically populate a lookup field on the Opportunity without having the user worry about it.
Once again, you start with the Flow since you’ll need it done and activated to call in Process Builder.
In this case, Process Builder will only be passing in the Opportunity ID, so it’s the variable you need to create first:
There’s typically only one Primary Contact Role record connected to an Opportunity, and first you have to find it. Yes, there could be more but in this case you only want to retrieve one anyway:
And when found, you want to save it to a new variable (assign null if not found so you don’t have an error – it will just update the record with a blank value which is fine):
Now you just need to update the Opportunity ID you already have with the Contact ID you just got.
Make sure your Flow has its start element and the pieces are connected. Save and Activate.
The tricky part of the Process is that you can’t fire it from the Contact Role record being created. Process Builder can’t touch Contact Role at all. So instead, your Process Builder criteria needs to be on whether or not the Primary Contact role has a value or not. If it’s blank, then Process Builder will fire the Flow that goes looking for the Primary Contact.
This is similar to the formula I used above in the other example, except it’s using the drop down conditions. As I said, go with what works.
And as before, your action is simply to launch the Flow you already created:
What do you think? Pretty easy, huh?