Validation rule and by pass validation rule for specific field and profile

opportunityvalidationvalidation-rule

I have a validation rule on Opportunity that will prevent user from update to Opportunity when Opportunity reach Closed Won.
This will only allow some specific profile to update to Closed Won Opportunities.
This is what the validation rule look like:

$Profile.Name <> "System Administrator"     
&&
Text(StageName) = "Closed Won"
&&
NOT(ISCHANGED(LeadSource))

Now I want to make an exception for a group of users in Profile "Sales Executives" so they will be able to update to a checkbox field call "Checked Opp" when opportunity in Closed Won stage so I make change it to this

$Profile.Name <> "System Administrator"     
&&
Text(StageName) = "Closed Won"
&&
NOT(ISCHANGED(LeadSource))
&& 
($Profile.Name <> "Sales Executive"     
&&
NOT(ISCHANGED(Checked_Opp__c)))

But the problem is when I change Checked Opp field and any other field like Opportunity Name then then this validation rule is NOT running. Any suggestion for my case ?

Best Answer

This is an inherent limitation of validation rules. They're just not good for things like "only allow this one field to be changed".

Your choices here are:

  • Just accept this limitation, and keep your validation rule
  • Create a new record type, which allows you to assign a new page layout. That page layout can make all the other fields "read only" (only enforced through the UI). A trigger would be the best option to change the record type (last I tried, flow/PB/workflow field updates couldn't update relationship fields unless you hardcode the Id)
  • Get rid of this validation rule, and enforce it in a trigger instead (using SObject.addError()). You could make use of getPopulatedFields() on the new and old record instances to quickly and efficiently see if there are any other changes trying to take place.
Related Topic