function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
petec@i2isyspetec@i2isys 

Validation rule not working if value = 0

I have a rule to compare the number of hours being used in a custom object against the number of hours available on another custom object. The number of hours available on the other object is a roll up summary field. If the number of hours being used are less than available, everything works. If the number of hours being used are greater that hours available, the rule works and fires an error. But if the hours being used are exactly = to hours available, the rule is firing a validation error when it shouldn't. See debug code below:

29.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
15:20:52.069 (69354942)|EXECUTION_STARTED
15:20:52.069 (69408880)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Professional_Services_Training_Usage:new
15:20:52.069 (69421708)|VALIDATION_RULE|03d40000000H4xy|Cannot_Exceed_Hours
15:20:52.069 (69666941)|VALIDATION_FORMULA|(Training__r.Hours_Remaining__c - Hours_Used__c)< 0.0|Hours_Used__c=2.0 , Training__r.Hours_Remaining__c=2.0
15:20:52.069 (69675079)|VALIDATION_FAIL
15:20:52.069 (69691504)|CODE_UNIT_FINISHED|Validation:Professional_Services_Training_Usage:new
15:20:52.069 (69696463)|EXECUTION_FINISHED
phiberoptikphiberoptik
So (Training__r.Hours_Remaining__c - Hours_Used__c)< 0.0 is your validation rule and even when the equation results in 0, thus 0 < 0, it throws validation error?

Can you just for the hell of it, change 0.0 to 0 and see if it makes any difference?
phiberoptikphiberoptik
I just replicated your fields and validation rule in my org and it saves correctly when 2.0-2.0 < 0.0 is the result. Could it be because of the RUS field? Can you try creating a bogus Number field on the same object as Hours_Used__c, and change the validation to compare to that field instead of the RUS. It appears from your debug that its calculating the right values, but the RUS field is the ONLY difference between my test and yours. I used two number fields on the same object.
petec@i2isyspetec@i2isys
Yes, it used to be just 0 but would fail. So I changed it to 0.0 to see if that made a difference but it did not. I will try what you suggested in your other post about RUS and let you know. Thanks so much for the suggestions. Pete *Pete Castagnetta* | Director of Operations | *i2i Systems* | 707-575-7100 x118 | petec@i2isys.com | www.i2isys.com *This message, including files attached to it, may contain confidential information that is intended only for the use of the ADDRESSEE(s) named above. If you are not an intended recipient, you are hereby notified that any dissemination or copying of this information contained in this message, or the taking of any action in reliance upon the information is strictly prohibited. If you have received this message in error, please notify the sender immediately by reply e-mail and destroy any and all copies of the original message*
petec@i2isyspetec@i2isys
Yes, it is definitely something to do with RUS. I got it to work on a not RUS field. Any idea why the rule works on RUS fields except when the value = 0? *Pete Castagnetta* | Director of Operations | *i2i Systems* | 707-575-7100 x118 | petec@i2isys.com | www.i2isys.com *This message, including files attached to it, may contain confidential information that is intended only for the use of the ADDRESSEE(s) named above. If you are not an intended recipient, you are hereby notified that any dissemination or copying of this information contained in this message, or the taking of any action in reliance upon the information is strictly prohibited. If you have received this message in error, please notify the sender immediately by reply e-mail and destroy any and all copies of the original message*
phiberoptikphiberoptik
It may be the way the RUS calculates and the order of execution. A RUS may calculate AFTER a formula field or at the exact same moment, which might be the culprit. Unless someone else chimes in who has experienced this same thing and knows the reason, I would log a case with support and get clarification. Please report back if you get an answer!
petec@i2isyspetec@i2isys
Salesforce got back to me.  I don't know why this works but it does.  You just have to put ROUND in the formula:
ROUND((Training__r.Hours_Remaining__c - Hours_Used__c), 1) < 0

I tested it and it worked.
phiberoptikphiberoptik
Interesting. Wish I understood the logic in that, but glad it works. I just hope other people can easily find this question and your solution in the future because I am assuming people come across this often.