When creating an opportunity as of now opportunity contactrole is not mandatory.System should display error message "Opportunity Contact Role" is required to create an opportunity if system did not find up the "opportunity contact role" upon creation of the opportunity.You can use triggers and utility class
[SalesForce] Opportunity Contact Role is required to create an opportunity
Related Solutions
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:
I don't believe there's any equivalent to the Classic URL hack. This behavior is something you can automate, though, without writing any code.
Add a new lookup on Opportunity to Contact; call it Primary_Contact__c
, for example. Make sure, in your Quick Action on the Contact object, that that field is selected as the "Relationship Name". (Note that if there's only one relationship field between Contact and Opportunity, you won't get to choose - that field will be selected automatically).
Now, build a new Process. Set it to run on Opportunity creation only, with a single criteria node that looks for Primary_Contact__c
to not be blank.
Add an action to the criteria node to create a record, and configure it to create an Opportunity Contact Role using the Opportunity Id, the value of the Primary_Contact__c
field, and whatever Role your organization prefers.
Then your Quick Action should exhibit that same behavior you expect.
Best Answer
Opportunity Contact Roles (OCR) by definition cannot be created prior to the opportunity existing.
Thus, when a user saves a new opportunity, there will never be a related OCR.
You could do this if you wanted to prevent opportunity updates without a related OCR:
Pseudo code for trigger: