0

Hi I have a validation rule that works but another requirement came up where it needs to trigger for certain record types.

I've tried to add an extra AND before the validation rule to exclude a certain record type but it doesn't seem to work and doesn't trigger at all.

OR( 
AND( 
   RecordTypeId  <>  "012200000005KeL",


  AND(   NOT(REGEX(ShippingPostalCode, "\\d{3}")), 
           1 = CASE( ShippingCountryCode, 
          'FO', 1 , 
          'IS' , 1 , 
          'LS' , 1 ,  
            0 )),

AND(  
    NOT(REGEX(ShippingPostalCode, "^([0-9]{3}-[0-9]{4})?$|^[0-9]{7}+$")), 
       1 = CASE( ShippingCountryCode, 
          'JP', 1 ,   
            0 )),

 AND(  
    NOT(REGEX(ShippingPostalCode, "^([0-9]{2}-[0-9]{3})?$|^[0-9]{5}+$")), 
       1 = CASE( ShippingCountryCode, 
          'PL', 1 ,   
            0 )),


             AND(  
    NOT(REGEX(ShippingPostalCode, "^([0-9]{3} [0-9]{2})?$|^[0-9]{5}+$")), 
       1 = CASE( ShippingCountryCode, 
          'SE', 1 , 
          'CZ', 1 ,
          'SK', 1 ,           
            0 ))))
2

The OR is in the wrong place:

AND( 
   RecordTypeId  <>  "012200000005KeL",
OR( 


  AND(   NOT(REGEX(ShippingPostalCode, "\\d{3}")), 
           1 = CASE( ShippingCountryCode, 
          'FO', 1 , 
          'IS' , 1 , 
          'LS' , 1 ,  
            0 )),

AND(  
    NOT(REGEX(ShippingPostalCode, "^([0-9]{3}-[0-9]{4})?$|^[0-9]{7}+$")), 
       1 = CASE( ShippingCountryCode, 
          'JP', 1 ,   
            0 )),

 AND(  
    NOT(REGEX(ShippingPostalCode, "^([0-9]{2}-[0-9]{3})?$|^[0-9]{5}+$")), 
       1 = CASE( ShippingCountryCode, 
          'PL', 1 ,   
            0 )),


             AND(  
    NOT(REGEX(ShippingPostalCode, "^([0-9]{3} [0-9]{2})?$|^[0-9]{5}+$")), 
       1 = CASE( ShippingCountryCode, 
          'SE', 1 , 
          'CZ', 1 ,
          'SK', 1 ,           
            0 ))))

Here, with this modification, we're saying if the Record Type is a specific Id, and one of three different AND conditions is true (the OR logic), then fire the validation rule.

The way it was written originally, all four of the AND conditions would have to be met, which would never happen.


Coincidentally, I recommend using $RecordType instead:

AND(
  $RecordType.Name = 'Some Specific Type',

Which is more portable across orgs instead of using a hardcoded ID value.

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.