1

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? Commented May 21, 2020 at 17:55

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .