I'm trying to come up with a way to require every new Opportunity to have a Contact Role associated with it upon creation. The issue I'm running into is the stupid "Recently Viewed" Opportunity List View. It's the only place left that would allow a user to create an Opp without associating a Contact Role. I have a VF page that redirects the user to an error message when trying to create an Opp using this method. 

<apex:page standardController="Opportunity">
     Please create this Opportunity from the associated Contact.

This works great, except when I now create an Opportunity frome the Contact, there is for some reason no associated Contact Role on the Opp. Would really appreciate any direction. Thanks!

  • We have the exact same setup. Im pretty sure the issue is that you are using a custom button on contact to create the opportunity, and you are not passing the contact ID. Are you in classic or lightning? Can you share the code for the button?
    – gorav
    Sep 15, 2018 at 22:14
  • Hey Gorav-we're using LEX. But we're not using a custom button to create the Opp from the Contact-we're simply going to the Opp related list from the Contact and creating it from there. Sep 17, 2018 at 3:17
  • The new button on the opportunity list view and the new button on the contact should both be using your vf page. I don't see how it could only apply to one of them as you have to override the new opportunity button w your page. Are you absolutely sure of this? I'm in classic so I can check again re lightning, but I don't see how it could be done the way you describe!
    – gorav
    Sep 17, 2018 at 11:11

2 Answers 2


Welcome to StackExchange, Patrick!

It's really difficult to cut off all avenues for creating an opportunity. If someone were to use DataLoader, or Salesforce for Outlook, or etc, they could create an opp without hitting any of the roadblocks!

I'd go back to the business and question the assumption: Do they really need to prevent opportunities from being created without a contact? Would it be good enough (or better) to prevent opportunities from moving past a certain stage without a contact assigned? An argument in favor of the latter: If a sales rep wanted to open an opportunity but didn't have the best contact's info, the rep might create a bogus contact just to get things going. The current business requirement is encouraging that.

If you can go with preventing the opp from moving past a given stage without a contact role assigned, then you can use a before update trigger (or a visual flow) to enforce the rule. Here's one example:


  • Thanks for the feedback, Shane. Unfortunately, having every Opp have an associated Contact Role is a strict requirement regardless of stage, for the Marketing team's purposes. We are already using essentially the same trigger and validation rule that your link alludes to. The only gap is making sure Opps get an associated Contact Role right off the bat. I ended up writing a trigger that populates the OCR upon Opp creation, after spending several hours looking into this and realizing that there just doesn't seem to be a silver bullet for this dilemma. Sep 17, 2018 at 3:22
  • Interesting. So you're using a trigger instead of overriding the New opportunity buttons? How are you determining which contact to use? Sep 30, 2018 at 21:41
  • 1
    Hi Shane-I created a Lookup field called "Primary Contact" and made it required when creating/editing an Opp. The Primary Contact Role gets created based on the Contact added in the Lookup field. Oct 1, 2018 at 22:41

The way I would fix this problem is to create a flow to create an opportunity and link the contact to the contact role during the flow. I'd then see if you could remove the opportunity tab altogether, replacing it with the flow you create.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.