1

I am trying to throw an error, when the first name, city, street is not entred for the record type selected ie: can be prospect or member. But when trying to save the member it does not throw the error. my syntax within the VR is as follows;

AND(($RecordType.Name = "Member" || $RecordType.Name = "Prospect"),
OR(ISBLANK( PersonMailingCity),
ISBLANK( PersonMailingStreet ),
ISBLANK( PersonMailingPostalCode ),ISBLANK( FirstName)))

&&
(NOT(OR( ISBLANK(Phone ),
REGEX( Phone ,"(\\D?[0-9]{3}\\D?)[\\s][0-9]{3}-[0-9]{4}"))))
&&
NOT($User.BypassVR__c)

where am i committing a mistake?

1
  • What is the value of phone and bypassvr__c when you do this? If the reflex for the phone is to validate correct format then if it is correct you vr rule will evaluate to false
    – Eric
    Dec 20, 2018 at 5:22

1 Answer 1

3

First, let me start off with some advice.

Pro Tip #1

To provide a more user-friendly experience, use multiple validation rules, one for each field to validate. This will mark all fields that are missing separately.

Pro Tip #2

Use proper indentation and avoid mixing &&/|| and AND/OR. Mixing styles makes the rule harder to read. Choose one and stick with it, it'll make your life easier.


Problem #1

Your validation rule's logic can only fire when city, state, postal code, or first name is empty, and the phone is not blank and does not match the pattern.

You would need to put the phone block in with the rest.

Problem #2

We want to error when the phone is blank OR does not meet the pattern. By de Morgan's laws, we can translate your code to:

AND(
    NOT(ISBLANK(Phone)),
    NOT(REGEX(Phone ,"(\\D?[0-9]{3}\\D?)[\\s][0-9]{3}-[0-9]{4}"))
)

This is not the same logic as I just described, which should actually be:

OR(
    ISBLANK(Phone),
    NOT(REGEX(Phone ,"(\\D?[0-9]{3}\\D?)[\\s][0-9]{3}-[0-9]{4}"))
)

Here's what your rule should look like:

AND(
    OR(
        $RecordType.Name = "Member",
        $RecordType.Name = "Prospect"
    ),
    OR(
        ISBLANK( PersonMailingCity),
        ISBLANK( PersonMailingStreet ),
        ISBLANK( PersonMailingPostalCode ),
        ISBLANK( FirstName),
        OR(
            ISBLANK(Phone),
            NOT(REGEX(Phone ,"(\\D?[0-9]{3}\\D?)[\\s][0-9]{3}-[0-9]{4}"))
        )
    ),
    NOT($User.BypassVR__c)
)

(or, you can use || and &&, but I recommend you avoid mixing and matching)


Edited: Found an inverted logic bug that would have had incorrect results.

0

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.