+ Start a Discussion

Validating Opp Contact Role fields from Custom Button on Opps Tab

Professional version with API
We have a custom button with exec javascript that validates a series of fields based on the user´s role before they can submit the Opp for approval by their Sales Mananger. All the standard validation works great and has been easy to access and program however I cannot figure out how to access the Opportunity Contact Role object from the native options within Salesforce to validate that a Role has been chosen, the Primary has been set, etc . . .
Futhermore there is no way create any valildation rules on the Opportunity Contact Role field directly or indirectly. For example if I wanted to create a validation rule on the Stage field that checks to see that the "Primary" contact has been chosen from all the contacts on the Opportunity Contact Role object when the Stage has been set to "Sold" there is no way to query the checkbox value on the "Primary" field.
What we want to accomplish is that no Sales Order goes forward without the "roles" of all the Opportunity Contact Roles being define and without a "Primary" chosen from all the contacts.
Does anyone have any ideas how this can be done?
thanks, crmzepher
We are having the same problem and would like to go a step further and validate that at least a contact has been chosen. 

Campaign management for contacts are basically useless if they are not being forced to chose a contact role for an opportunities.

Did you find a way to track 'contact roles' from the 'opportunities' tab? I need to create a workflow task that fires off an email if an opportunity is closed with 0 contact roles.
Wes BarnesWes Barnes
hello --
I am also interested in finding out if you were able to engineer this as we are trying to do the same thing.  I can implement this as an SForce control if needbe but would prefer to simply have validation rules.  My guess is that validation rules will not work as contact roles are a related list and not a direct object in the opportunity.  Regardless, there should be a way to force this somehow.
There is an appexchange pkg available to validate that a primary contact has been selected for an opportunity.  Link to it is here:  https://www.salesforce.com/appexchange/detail_overview.jsp?id=a0330000006lIFtAAM
Perhaps looking at this and the code behind it will help you guys out.
Wes BarnesWes Barnes

Rhonda --


I am sorry for not having responded to this before now but appreciate your reply.  I have implemented this app in my dev sandbox and have started doing some testing.  I am not sure exactly what I need to put into the case statement after I have identified my stagename, here is what I have:


CASE( StageName , "Stage to be Required 1", 1, "Verbal Acceptance - 75%", ?,?) 


I have a stage called:   Verbal Acceptance - 75% and want any stage or probability above 75% to have a primary contact and role deifned.  I would love to make a rep specify the 4 roles that we want for our projects but will take a single contact role if I can get that.


Any help is appreciated. 




The only values you need the CASE statement to lookup are the stage values that you want to trigger this rule. 


You want the formula field to return a 1 to trigger the rule and a 0 if you don't so...



CASE( StageName , "Verbal Acceptance - 75%", 1,0)



I did it this way in Sandbox and it worked for me using my required stage values.


Wes BarnesWes Barnes
Perfect that is what I needed.  This is working perfectly.  Just a side note question, is it possible to check for a specific role value instead of just a primary contact?
Chirag MehtaChirag Mehta
Is there a way to show in the Contact object that a contact is the primary contact listed in an attached opportunity?
James ACTJames ACT
I am also trying to write a validation rule on the opportunity based on the presence of a "Decision Maker" contact. You referenced an app on the exchange, but the link doesn't take you to the specific app. Could you tell me the name of the app, so I can grab it?
You can write an APEX trigger on the opportunity object that when triggered, updates a contact field in the opportunity's primary contact record indicating that this contact is the primary.
James ACTJames ACT

Is it possible to go the other way? I'm trying to require a contact decision maker before an opportunity would automatically change stages (using workflow rules).



Have you looked into the free app from the linked posted by rpr2 on the first page of this discussion?  We used that and it works great.



I am interested in this appexchange pkg, but can't seem to get there from the link rpr2 provided back in December.  We don't necessarily care about a primary Contact being associated with the Opportunity, but just want ANY Contact before the Oppty can be Closed!





Maybe the link changed, here it is http://sites.force.com/appexchange/apex/listingDetail?listingId=a0N300000016cbDEAQ.


This app includes APEX and custom formulas that make an opportunity primary contact required a at the opportunity stages you specify in the custom formula the app creates. 


I would recommend that you install this in your sandbox environment (if you have one) first and test it out to make sure it works.  This app may trigger some of your custom validation rules or workflow rules that the original APEX does not account for.

Message Edited by jvolkov on 05-08-2009 08:39 AM

That link worked.  I will definitely try this in our sandbox first. That is basically where I live at the moment. 


Many thanks


Is there a way to only make the Contact roles required after the intial Opportunity creation? Since Contact roles cannot be added in Edit mode, how do I only make Contact required after the initial Oppty is created?  As is, users can create an Opportunity in any stage with the exception of Closed/Won. Was curious how other companies deal with this. 




Initially we ran into the same problem.  What we did is made the custom formula in the app only return true for all stages other than the first stage.  Then make the first stage a requirement using a validation rule.  This ensures that all opportunities start off at the same stage which does not require a primary contact role.  Then if the user wants to change the stage they must first enter a primary contact role for the opportunity.


Also, creating opportunities from contacts instead of accounts will acheive this.


Thanks. I had both of those thoughts as well.  Regarding creating an Oppty from the Contact instead of Account- I am having trouble figuring out how to restrict the New button on the Oppty tab and Create New section on side bar only for Opptys while keeping it on the Contact layout. Any tips?  I think I need to take a beginner developer/programming course :smileyhappy:

Yes a validation rule would be great. I also wasn't able to find the app mentioned above.