0

I'm having an issue with the following Validation rule, the issue only arose yesterday for the first time. The rule is as follows:

AND( 
    ISPICKVAL(Sync_to_Sage__c, 'Ready to Sync'), 
    Total_Amount__c != Labour_Net_Amount__c + Parts_Net_Amount__c 
)

The issue is that the validation rule is being set off even though the total amount is equal to the labour + Parts amount

I've queried the results of total amount, Labour net amount and Parts net amount in the Dev Console and the three results are adding up correctly. All three fields are Roll up summary fields.

Does anyone have any suggestions for what may be causing this?

  • 1
    What's the issue? – Martin Lezer Mar 23 '17 at 15:37
  • Sorry, I wasn't clear. The issue is that the validation rule is being set off even though the total amount is equal to the labour + Parts amount – denisoleary Mar 23 '17 at 15:41
  • If Total_Amount__c, Labour_Net_Amount__c, and Parts_Net_Amount__c are all rollup summary fields, (with Total_Amount__c presumably being the sum of the other two) why do you need a validation rule at all? A case could be made to verify that the rollups behave correctly via a unit test, but having a validation rule to verify that a calculation that isn't performed by a human turned out correctly seems rather pointless to me. – Derek F Mar 23 '17 at 15:46
  • My previous comment aside, when you query the values of Labour_Net_Amount__c and Parts_Net_Amount__c, how many decimal places is Salesforce showing? It's entirely possible that at least one of these fields on at least one of the child records has a deviation of an incredibly small fraction of your currency, or some other rounding error that only appears when storing values from other calculations (as opposed to directly using the results of those other calculations). – Derek F Mar 23 '17 at 15:52
  • 1
    Sounds like your validation rule belongs on the child object instead of the parent object. Preventing people from entering a value on 'Other' records in the first place is better (as opposed to allowing them to do it at first, and then detecting and complaining about it, and forcing your users to fix their mistakes all at once). Beyond that, I think you'll need to execute some anonymous apex (basically, re-create your rollups, but in Apex, and debug the output) to get any more information about what's going wrong. – Derek F Mar 23 '17 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.