0

I wrote a validation rule I would like to make better. It should show and error message if the sum of a number of fields must equal the value in another field when saving a record. If any field has blank/null value it should treat it as zero. I would like to know is there a better or more efficient(refactor) way of writing this validation rule.

  (
    IF( ISBLANK(Payment_1__c) , 0, Payment_1__c) +
    IF( ISBLANK(Payment_2__c) , 0, Payment_2__c) +
    IF( ISBLANK(Payment_3__c) , 0, Payment_3__c) +
    IF( ISBLANK(Payment_4__c) , 0, Payment_4__c) +
    IF( ISBLANK(Payment_5__c) , 0, Payment_5__c) 
  ) <> Total_Amount__c
1
  • Probably use NULLVALUE() formula will give you a slightly shorter rule? May 21 '20 at 17:55
1

Use BLANKVALUE:

BLANKVALUE(Payment_1__c,0)+
BLANKVALUE(Payment_2__c,0)+
BLANKVALUE(Payment_3__c,0)+
BLANKVALUE(Payment_4__c,0)+
BLANKVALUE(Payment_5__c,0)
<> Total_Amount__c

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.