Validation Rule not firing correctly - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Admin -ChartisAdmin -Chartis 

Validation Rule not firing correctly

My use case is I have a group of 5 % fields.   If any of the fields are not null, then their sum must be 100%.

Below is the formula, it does not work in the validation rule.  The weird thing is I create a custom field with the same formula and then have the validation rule evaluate the custom field it works fine.   

Does this have to do with evaluation order or what?


NOT(OR(Override_Pursuit_Lead_Credit__c + Override_Contributor_1_Credit__c + Override_Contributor_2_Credit__c + Override_Contributor_3_Credit__c + Override_Contributor_4_Credit__c = 1.0, Override_Pursuit_Lead_Credit__c + Override_Contributor_1_Credit__c + Override_Contributor_2_Credit__c + Override_Contributor_3_Credit__c + Override_Contributor_4_Credit__c = 0.0))
Best Answer chosen by Admin -Chartis
Tony TrinhTony Trinh
Hello Chartis,

Give this a try:
AND(
OR(
  NOT(ISBLANK(Override_Pursuit_Lead_Credit__c)),
  NOT(ISBLANK(Override_Contributor_1_Credit__c)),
  NOT(ISBLANK(Override_Contributor_2_Credit__c)),
  NOT(ISBLANK(Override_Contributor_3_Credit__c)),
  NOT(ISBLANK(Override_Contributor_4_Credit__c))
),
Override_Pursuit_Lead_Credit__c + Override_Contributor_1_Credit__c + Override_Contributor_2_Credit__c + Override_Contributor_3_Credit__c + Override_Contributor_4_Credit__c <> 1
)
This says, if any of the fields are not blank, then check to see if that sum is 100%
 

All Answers

Tony TrinhTony Trinh
Hello Chartis,

Give this a try:
AND(
OR(
  NOT(ISBLANK(Override_Pursuit_Lead_Credit__c)),
  NOT(ISBLANK(Override_Contributor_1_Credit__c)),
  NOT(ISBLANK(Override_Contributor_2_Credit__c)),
  NOT(ISBLANK(Override_Contributor_3_Credit__c)),
  NOT(ISBLANK(Override_Contributor_4_Credit__c))
),
Override_Pursuit_Lead_Credit__c + Override_Contributor_1_Credit__c + Override_Contributor_2_Credit__c + Override_Contributor_3_Credit__c + Override_Contributor_4_Credit__c <> 1
)
This says, if any of the fields are not blank, then check to see if that sum is 100%
 
This was selected as the best answer
Admin -ChartisAdmin -Chartis
Makes sense are you saying I have a logic problem though?    Kinda confused why mine would work as a Custom Field but not in the validation rule directly.
Tony TrinhTony Trinh
It could be how the blank field handling is done in a formula field. Formulas default to blank fields being zeroes.
Steve MolisSteve Molis
You can do a quick test of your Validation Rule Formula like this 

Tips & Tricks: Using Checkboxes to test Validation Rule Formula Logic
https://success.salesforce.com/answers?id=9063A000000psiUQAQ
Admin -ChartisAdmin -Chartis
Steve - thanks for the tips.   That's exactly how I debugged mine however, the checkbox was behaving differently than the validation rule.

In the end made the validation rule evaluate if the checkbox was true or false and it worked.   Weird, makes me think i have some error I'm not thinking about.