Validation Rule firing even when StageName is not Closed Won - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Tarang SharmaTarang Sharma 

Validation Rule firing even when StageName is not Closed Won

Hi Everyone,

I have a requirement to make field non-editable when an Opportunity for a specfiic record type is "Closed Won". For some reason, my validation rule is firing even when a Stage is selected that isn't "Closed Won". Any ideas on what I'd have to modify in my validation rule? 
 
RecordType.DeveloperName = "PP_Monetary_Opportunity"
||
RecordType.DeveloperName = "PP_Non_Monetary_Opportunity"
&&
ISPICKVAL(StageName, "Closed Won")
&&
$Permission.PP_Closed_Won_Opps = FALSE
&&
OR(
ISCHANGED(Name),
ISCHANGED(Personal_Plan_Contact__c),
ISCHANGED(Type),
ISCHANGED(Category__c),
ISCHANGED(Amount),
ISCHANGED(Contribution_Frequency__c),
ISCHANGED(Destination_Policy_Number__c),
ISCHANGED(External_Institution__c),
ISCHANGED(StageName),
ISCHANGED(Probability),
ISCHANGED(Comments__c),
ISCHANGED(AccountId),
ISCHANGED(CloseDate),
ISCHANGED(CreatedById),
ISCHANGED(LastModifiedById)
)


Thanks
​​

Best Answer chosen by Tarang Sharma
Mikey BrownMikey Brown
Hi Tarang, 

There could potentially be a problem with the first part of your validation as well where you have 
RecordType.DeveloperName = "PP_Monetary_Opportunity"
||
RecordType.DeveloperName = "PP_Non_Monetary_Opportunity"

Essentially, if any of those record types are in place, the validation rule looks like it will fire, regardless of any of the other contditions, such as field value name.

I would try changing that part of the rule to:
OR(RecordType.DeveloperName = "PP_Monetary_Opportunity",
RecordType.DeveloperName = "PP_Non_Monetary_Opportunity")
&&
ISPICKVAL(StageName, "Closed Won")
&&
$Permission.PP_Closed_Won_Opps = FALSE
&&
OR(
ISCHANGED(Name),
ISCHANGED(Personal_Plan_Contact__c),
ISCHANGED(Type),
ISCHANGED(Category__c),
ISCHANGED(Amount),
ISCHANGED(Contribution_Frequency__c),
ISCHANGED(Destination_Policy_Number__c),
ISCHANGED(External_Institution__c),
ISCHANGED(StageName),
ISCHANGED(Probability),
ISCHANGED(Comments__c),
ISCHANGED(AccountId),
ISCHANGED(CloseDate),
ISCHANGED(CreatedById),
ISCHANGED(LastModifiedById)
)

Thanks,
​​​​​​​Mikey

All Answers

Mikey BrownMikey Brown
Hi Tarang, 

There could potentially be a problem with the first part of your validation as well where you have 
RecordType.DeveloperName = "PP_Monetary_Opportunity"
||
RecordType.DeveloperName = "PP_Non_Monetary_Opportunity"

Essentially, if any of those record types are in place, the validation rule looks like it will fire, regardless of any of the other contditions, such as field value name.

I would try changing that part of the rule to:
OR(RecordType.DeveloperName = "PP_Monetary_Opportunity",
RecordType.DeveloperName = "PP_Non_Monetary_Opportunity")
&&
ISPICKVAL(StageName, "Closed Won")
&&
$Permission.PP_Closed_Won_Opps = FALSE
&&
OR(
ISCHANGED(Name),
ISCHANGED(Personal_Plan_Contact__c),
ISCHANGED(Type),
ISCHANGED(Category__c),
ISCHANGED(Amount),
ISCHANGED(Contribution_Frequency__c),
ISCHANGED(Destination_Policy_Number__c),
ISCHANGED(External_Institution__c),
ISCHANGED(StageName),
ISCHANGED(Probability),
ISCHANGED(Comments__c),
ISCHANGED(AccountId),
ISCHANGED(CloseDate),
ISCHANGED(CreatedById),
ISCHANGED(LastModifiedById)
)

Thanks,
​​​​​​​Mikey
This was selected as the best answer
Parul GuptaParul Gupta
Hi Tarang

Please use ISPICKVAL(PRIORVALUE(StageName),"Closed Won") instead of ISPICKVAL(StageName, "Closed Won")

Thanks
Tarang SharmaTarang Sharma

Hi Mikey and Parul, 

I see my mistakes now. Thanks for the advice! 

Tarang