+ Start a Discussion
morleymorley 

How to validate for Opportunity Contact Role?

Hi there,

I'm trying to create a validation rule to ensure that when a user creates an Opportunity that they also create at least one Opportunity Contact Role.

I'm pretty sure this isn't possible, because validation would have to occur on the edit page of the Opportunity, but OCRs aren't created there. However, when I go to create a validation rule for Opportunity, in the list of available merge fields, there's a field called ContactID. What does that refer to and would it be useful for my purpose?

Thanks for any help!



Morley.

sfdcfoxsfdcfox
Curious. I see this ContactId field in validation rules, but it doesn't appear in the docs or even in the describe call. I believe it's probably related to person accounts, and is probably only usable in that scenario (eg. to determine if the opportunity is tied a person account). I don't have person accounts, so I can't test this... can anyone confirm or deny this?

However, to answer your original question, no, you can't validate against related items. Even if you could, it would be a chicken-and-egg (eg. "Chinese Trap", "Catch-22") problem. You wouldn't be able to create new opportunities; to create the opportunity you'd have to add the contact role, but you can't add contact roles until you create the record.

Of course, you could code around this, but in that case, it still wouldn't force the users to add roles until they tried to edit the record later. Enterprise Edition organizations (or if you have the API) could override the edit button with an S-Control. In this case, the code would check to see if there are contact roles on the existing record; if not, force them to the contact roles page, otherwise allow the edit. Or, an S-Control could force a user looking at the detail page to add contact roles if there are no associated contact roles for the opportunity.

The Apex Code feature would likely allow something like this to work entirely on the Salesforce server in the future, allowing greater flexibility (or, even better, automatically adding contact roles so the users don't have to remember).

~ sfdcfox ~
krprkrpr

You can try this functionality with a custom button.

Bryce CBryce C
Another potential solution is creating a custom Opportunity child object to use for Contact Roles instead of the built-in object. The custom object will be much more flexibile, will allow for triggers and customization of the Page Layout, and you can use a roll-up function + functions on the custom object to do a lot of interesting validation.