Pull Primary Contact Role into custom Lookup Field on Opportunity - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Jessica PeroneJessica Perone 

Pull Primary Contact Role into custom Lookup Field on Opportunity

Hi everyone, 

This seems to be a common question and I have made mulitple attempts at getting this to work based on articles found online, but none seem to work. I need to populate a custom Contact LookUp field I created on our Opportunity record with the Contact that has been marked as the Primary Contact in the Contact Roles on the Opportunity. The purpose of this is to simply be able to pull the Contacts first name into email templates as needed.

I first created a Flow. 
User-added image
Record LookUp:
User-added image
Record Update:
User-added image
Then a Process:
User-added image
Process Criteria:
User-added image

Process Immediate Actions-can't fit but is
Set Flow Variable: varOpportunityId
Type: Field Reference
Value: [Opportunity].Id

The Flow is Autolaunched and active and the Process is also active. However, nothing is triggered upon opportunity record update or edit. Am I missed a step somewhere? Any help is appreciated!

Thank you
 
Best Answer chosen by Ed (salesforce.com) 
Steve MolisSteve Molis
Yes, it needs to be Datatype: Lookup(Contact)

All Answers

Steve MolisSteve Molis
I've done this (in reverse)  I created a custom Lookup(Contact) field on the Opportunity object, then I use the Process Builder to pass the OpportunityId and ContactId to a Flow which creates a new Opportunity ContactRole record and sets that Contact Role as the Primary. 
Jessica PeroneJessica Perone
Hi Steve,

Unfortunately, my team does not want to take that approach. The reason is that our Sales team inputs multiple Contact Roles. They want to do everything in one place-not add all Contact Roles in one place then go to a differnt field to add the Primary Contact. The Opportunity later gets passed to another department who will then send an email to whoever the Primary Contact is. We are using custom HTML email templates so they have their fancy signatures, but this makes it so they can't edit the templates to simply plug in the Primary Contacts first name. It has to be a merge field in the template. So I need my custom "Primary Contact" lookup field on the Opportunity page to auto populate when the Primary Contact is added in the Contact Roles. 
Jessica PeroneJessica Perone
Wait - I was just testing again. I added a name to my Primary Contact custom field manually then deleted it. All of a sudden the Primary Contact in the Contact Roles autopopulated! Hmmmm... 
Jessica PeroneJessica Perone
I have found that my Primary Contact custom lookup field will only populate with the Contact Role Primary Contact if I add a value to the field then delete it. It does not populate when I add the Primary Contact Role or even when I edit the Opportunity record in any other way and save it. ? 
Jessica PeroneJessica Perone
I removed the check box in my Process where I defined my criteria for: "Do you want to execute the actions only when specified changes are made to the record?" The field now updates anytime an edit is made to the Opportunity. This now appears to be correct and working. I only hope this doesn't have any adverse affects! 
 
Harold CarlsonHarold Carlson
Is there any way to auto-populate the lookup field on the opportunity without having to "touch" and save the opportunity?  My users are having issues with having to modify the opp in same way to make the decision maker stick.
Jessica PeroneJessica Perone
Hi Harold,

I think you would need to do a mass edit using Data Loader to trick the system into triggering the flow and process. We are so far just advising our team to check if the field is already populated and if not to cilck edit and save to update the field. 
Jenny Van ReesJenny Van Rees
When I create this exactly as you and Judi Sohn have described, I get "contact ID" in my Primary Contact ID field. How do i get this to display name? Do I have to make that field a formula? and what would that be. Thanks for the help!
Steve MolisSteve Molis
Jenny, what is the datatype of your Primary Contact ID field?  Is it Text, or a Lookup(Contact) field?  

Can you post screenshots?
Jenny Van ReesJenny Van Rees
Its just a text field, is that my problem? i need to make it a lookup!
Steve MolisSteve Molis
Yes, it needs to be Datatype: Lookup(Contact)
This was selected as the best answer
Jenny Van ReesJenny Van Rees
DOH i hate it when its an easy fix i over looked. Thanks Steve, i owe you a beer at dreamforce this year.
Marisa SkeltonMarisa Skelton
Wow!  Jessica, I experienced the same thing as you when you say "I have found that my Primary Contact custom lookup field will only populate with the Contact Role Primary Contact if I add a value to the field then delete it. It does not populate when I add the Primary Contact Role or even when I edit the Opportunity record in any other way and save it. ? "  I uncheked "Do you want to execute the actions only when specified changes are made to the record?" but it is still not working.  Everything is exactly as you have done. 

How did you get it to work???

Thanks,
Marisa
Jessica PeroneJessica Perone
Hi Marisa,

If you unchecked the box under "Do you want to execute the action only when specified changes are made to the record?" and everything else is the same. It should work. Ensure the field you are trying to populate is a Contact Lookup field and that your Process is active. Then try updating a test Opportunity with a new Primary Contact Role. 
Marisa SkeltonMarisa Skelton
Hi Jessica​,

Thank you for getting back to me.  I think I have found the issue but don't have a solution yet.  When we convert a lead, the person is automatically added to the Contact Roles related list on the opportunity, but the Primary Contact field on the Opportunity layout does not update until I edit the opportunity.  Do you know how the process would kick off from a lead conversion.  I don't think it is considered an update to an opportunity when the contact role is added upon create.

Thanks,
Marisa
Jessica PeroneJessica Perone
Hi Marisa,

Ah... I see. Unfortunately, I do not know how to get this kicked off during the Lead conversion process. Luckily for us, the Opportunity is always edited somehow before we actually need the field data for an email. I wonder if an additional workflow rule or process could be setup to trigger the field to be updated?
Barbara KuntzBarbara Kuntz
Similar issue: trying to expose the primary contact email and phone number on the opportunity object. 

I think what I'm reading above is that I can't do this using a formula text field, but need to use a lookup?  I'm unsure how to do that.  I can create a lookup to contact but how then to expose the email?  Am sure I'm missing something really basic.
Jessica PeroneJessica Perone
Hi Barbara,

I don't know if you can pull the email or phone number to make it show on the record. If you have the Contact lookup popuated, you can pull that information from the Contact into email templates or other documents if needed. 
Anne BrockAnne Brock
Jessica, this was so very helpful to me! thanks for posting all the screen shots. 
Jessica PeroneJessica Perone
Hi Anne,

So glad to know it has helped you out! You're most welcome. :)
Diana MoizeDiana Moize
Hello Jessica. I am stuck in the process. I cannot find {!varOpportunityID}. Is it under Create New, Global Constant or System and global variable? Also the field Contact ID is not avaialbe. What I am doing wrong? Thanks
Peter NogesPeter Noges
hey @Diana Moize, you have to Create New, and name it varOpportunityId or whatever you choose to name it.  It is in the process builder actions where you specify to launch the flow, and as part of that there will be options to map fields (such as Id  as in Opportunity Id) to your variables.  Process builder will recognize that you have variables defined in your flow and in turn will allow you (in process builder) to assign values to them before firing your flow which uses them.
Diana MoizeDiana Moize
@Peter. Thanks Peter I did that part. It looks like the Record Lookup and the Record Update in the flow is not conected to anything. I have that warning. I think I miss one step right?

 
Diana MoizeDiana Moize
@Jessica Perone
If have unchecked the box under "Do you want to execute the action only when specified changes are made to the record?" Also the field that I am trying to populate is a Contact Lookup field and that your Process is active. Then when I update the test Opportunity with a new Primary Contact Role nothing show up. Any idea why this is not working? Thanks
Jessica PeroneJessica Perone
Hi Diana,
Your Flow and Process are both on the Opportunity object? Sounds like if everything you have set up matches the screen shots above with the few tweaks you mentioned you already did, it should work. I would compare your settings on each page to ensure they match. 
Ava LichaucoAva Lichauco
Hi all, 

I'm a beginner SFDC user (~ 2 months) and it's my first time posting in this awesome community! I'm hoping you guys could help me out as I'm trying to tackle a similar problem.

I was following the steps listed on this thread as I have a custom lookup field under Contacts (called "Opportunity") that I want to populate with the most recent Opportunity tied to the Contact based on Opportunity Contact Roles attributes (i.e., Role = "Decision Maker"). I created a similar Record Lookup and Record Update in Flows and a similar Process Builder action, though no update to my Contact record is triggered. I've included screeshots below. 

Note that I am triggering the change in the Contact record from a quick action I built within the Contact record itself. This quick action allows a user to create an Opportunity from the Contact Record, which then triggers an Opportunity Contact Role update where that Contact is the Primary Contact and his/her role = Decision Maker.

I appreciate ANY of the help that I can get!! 

Record Lookup:
Record Lookup

Record Update:

record update
Process Builder:
pb1

pb2pb3

Immediate Action is:
Flow I specified above
Set Flow Variables: 
  • Flow Variable = ContactID
  • Type = Field Reference
  • Value = [Contact].ID 

 
Ava LichaucoAva Lichauco
Here is a screenshot of the quick action I built from the Contact records page for your reference: 

sfdc

Thank you in advance again for any advice! :)
Anne BrockAnne Brock
I'm still having some problems with this myself; it seemed to work great, but sometimes the fields on the opportunity get blanked out. I don't know if it's the way the reps are adding the Contact Roles or something else; I ended up disabling the functionality until I have time to look at it.
Maxim MakarenkoMaxim Makarenko
Hi Anne,
Have you tried setting up Field History Tracking on the fields that get blanked out?
Anne BrockAnne Brock
Hi, Maxim, no, I haven't tried that. I haven't had a chance to get back to this workflow.
 
Ruth SmithRuth Smith
SteveMo - I was trying to do exactly what you did(in October 17) today - to start I created my custom lookup field but when I create an opportunity field FROM a contact the user has to still choose the contact. I am staring at this custom field, and another very similar that does fill in. I cannot figure out what I have not done right. I dont want the user to have to choose the contact if I can help it. I also expected the account field to autofill as long as the contact is related to one but it doesnt.  :-( 
We need emoticons here so I could have added a couple beer mugs. :-)
James BensonJames Benson
Would someone be so kind to show the configuration of that {!varOpportunityID}?
Paula JarvisPaula Jarvis
@Steve Mo I have a somewhat simiar situation and I am a complete rookie with FLOW. I want to pull ALL the Contacts within a specific Opportunity Contact Role and populate Contact Lookup Fields on the Opportunity in order to send out a Satisfaction Survey to these Contacts. I've started building the FLOW (see screen shot 1). I get stuck when I attempt to create the Variable. I do not see the Data Type = Lookup when I select CREATE NEW Variable (See screen shot 2). Would appreciate the assist here. Thank you in advance.

User-added image
User-added image
Steve MolisSteve Molis
I'm currently on vacation up in Boothbay Harbor Maine, not sure when I will be able to get online and take a look at it. Excuse the brevity I'm on my mobile
Ruth SmithRuth Smith
Paula - I am the worst at flows but did you see that with the last release they added ability to download templates? When you click new button it offers you templates. I was just wondering if you could download a template that is similar - would it help to look how it was done in template?
Ruth SmithRuth Smith
I have several also in my org that were built by admin before me who was more a developer. I would be happy to skype with you so we could look at how she did some of ours if you want? I might learn something too. 
Matt MullerMatt Muller
@Jessica Perone Thank you for sharing this, very helpful. I found a quick and painless way to update all opportunties' custom primary contact fields instead of having the sales team do it. 
  1. Go to Opportunities Tab
  2. Create a list view of all opps
  3. Add Custom Primary Contact Field to "Fields to Display"
  4. Select All
  5. Click in the Primary Contact Field box and edit all records
  6. Leave the update blank and hit save.
The end result is it tricks the process builder into kicking the process off and updates the Custom Primary Contact Field.

-Matt
Jessica PeroneJessica Perone
Hi Matt,

We are good now since we've been using this for some time. However, great tip! I'm sure this will help others just getting this setup. Thank you!

Jessica
Don EtchisonDon Etchison
Thank you for sharing this with the Community, @jessicaperone ! It worked like a charm for me. 
Brad BassingerBrad Bassinger
So I'm trying to implement this but seem to be getting stuck somewhere and when I have the flow and process active, the opportunity errors out and won't let me save anything.  I think its the final step that is tripping me up in the Process Builder.  

It does not seem to let me choose the [Opportunity].ID as the value to set the OppID variable as the immediate action.  When I try to select the field, I get this:
User-added image

What exactly am I missing here where I can't directly select the Opportunity ID?