0

I've been racking my brains on this. I have a business case whereby I need to enforce a validation rule on a pair of fields Renewal Date (date) field and Deal Value (currency) field. A user should not be able to enter a value for the date field, if the currency field is blank. I've built a validation rule for one pair of these fields with the logic as follows:

AND( 
    ISBLANK( Deal_Value_HB_APIX__c ),
    NOT(ISBLANK( Renewal_Date_HB_APIX__c ))
)

The above works just right. But there are four other pairs of these fields types which need to have the validation set for them also. Can this be achieved using a single validation rule?

Many thanks in advance for help received!

2
  • 2
    A single validation rule can only emit a single error message (either next to a specific field or on the top of the page). For that reason, the general recommendation is to keep validation rules specific (rather than general). If you're involving other fields, that's a sign that they should be separate validation rules.
    – Derek F
    Jan 4, 2023 at 17:43
  • Thank you Derek. I decided to go down this route, because they may be a need to specify other fields with this validation in future. I did not want to create a complex validation that could break when I try to enter new criteria in future.
    – rutho92
    Jan 5, 2023 at 10:12

1 Answer 1

0

You can do this but you need to make the error message more generic and place the error at the top of the page

OR (
  AND( 
    ISBLANK( Deal_Value_HB_APIX__c ),
    NOT(ISBLANK( Renewal_Date_HB_APIX__c ))
  ),
  AND( 
    ISBLANK( Field2__c ),
    NOT(ISBLANK( Date2__c ))
  ),
  AND( 
    ISBLANK( Field3__c ),
    NOT(ISBLANK( Date3__c ))
  ),
  AND( 
    ISBLANK( Field4__c ),
    NOT(ISBLANK( Date4__c ))
  )
)

Error message (at top of page):

Either Deal Value is required if Renewal Date entered OR
       Field2 is required if Date2 entered OR
       Field3 is required if Date3 entered OR
       Field4 is required if Date4 entered
3
  • Thanks cropredy - this worked when I tested it. I decided to take Derek's advice above and create separate validations so as to not complicate things if any future additions are needed. Good to know for future cases though
    – rutho92
    Jan 5, 2023 at 10:14
  • Derek's advice is good advice; I often follow it :-). The only plausible advantage of the combined approach above is ease of maintenance if all the branches follow a common pattern so you can readily copy-paste
    – cropredy
    Jan 5, 2023 at 17:18
  • 1
    Since I made that comment, I changed my mind and used the combined approach. I just felt that, like you said, I was creating too many validation rules to effectively serve the same purpose on different, but very similar in purpose fields. I tried to add a new line for my additional fields to the solution you posted above after copying and pasting, and it messed up the validation. Then I started from scratch and did them one by one and this worked. So that is what I plan to put in production :)
    – rutho92
    Jan 6, 2023 at 18:37

You must log in to answer this question.

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