Ask Search:
K CarmenK Carmen 

Validation Rule for Opp Contact Role Trigger

Hi All - I've written my Apex Trigger and deployed it but looks like I'm still having trouble. 

I want my users to get the error message that they must add a contact role on the opp before moving the opportunity to any other stage than the first one.
My rule below isn't working well. GAH! HELP!

AND 

NOT(Primary_Contact_Assigned__c), 
AND(OR(ISPICKVAL(StageName,'Value Proposition'),ISPICKVAL(StageName,'Proposal/Price Quote'),ISPICKVAL(StageName,'Negotiation/Review'), ISPICKVAL(StageName ,'Closed Won'),ISPICKVAL(StageName ,'Closed Lost'))))
Best Answer chosen by K Carmen
K CarmenK Carmen
OK - this seems to be working. Not sure if it's the best way to write it out, tho:
AND 
(OR(ISPICKVAL(StageName,'Value Proposition'),ISPICKVAL(StageName,'Proposal/Price Quote'),ISPICKVAL(StageName,'Negotiation/Review'), ISPICKVAL(StageName ,'Closed Won'),ISPICKVAL(StageName ,'Closed Lost')))&&(Number_of_Contacts_Roles_Assigned__c = 0)

All Answers

K CarmenK Carmen
I will also add - I did some additional testing and it looks like the problem is that the Contact Role has to be marked as Primary Contact.  Is there a way to add in the validation that if any contact role is added, even if it's not a primary, that the record can be saved?
K CarmenK Carmen
OR....perhaps there is a way to make the first contact role created default to primary?
K CarmenK Carmen
OK getting closer but need to make it say if the Number of Contacts Roles Assigned is blank or 0. Any help on h ow to write this would be greatly appreciated!

AND 

ISBLANK(Number_of_Contacts_Roles_Assigned__c), 
AND(OR(ISPICKVAL(StageName,'Value Proposition'),ISPICKVAL(StageName,'Proposal/Price Quote'),ISPICKVAL(StageName,'Negotiation/Review'), ISPICKVAL(StageName ,'Closed Won'),ISPICKVAL(StageName ,'Closed Lost'))))
K CarmenK Carmen
OK - this seems to be working. Not sure if it's the best way to write it out, tho:
AND 
(OR(ISPICKVAL(StageName,'Value Proposition'),ISPICKVAL(StageName,'Proposal/Price Quote'),ISPICKVAL(StageName,'Negotiation/Review'), ISPICKVAL(StageName ,'Closed Won'),ISPICKVAL(StageName ,'Closed Lost')))&&(Number_of_Contacts_Roles_Assigned__c = 0)
This was selected as the best answer