function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RajanRajan 

Trailhead Validation rule to check that a contact is in the zip code of its account.

Challenge is as below:--
To complete this challenge, add a validation rule which will block the insertion of a contact if the contact is related to an account and has a mailing postal code (which has the API Name MailingPostalCode) different from the account's shipping postal code (which has the API Name ShippingPostalCode).
Name the validation rule 'Contact must be in Account ZIP Code'.
A contact with a MailingPostalCode that has an account and does not match the associated Account ShippingPostalCode should return with a validation error and not be inserted.
The validation rule should ONLY apply to contact records with an associated account. Contact records with no associated parent account can be added with any MailingPostalCode value. (Hint: you can use the ISBLANK function for this check)


--------------------------------------------
My validation rule is as attached pictureUser-added image

And Error is- Challenge Not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic
Rupal KumarRupal Kumar
Hi,
Try this-
 
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode
)

Thanks
Rupal kumar
RajanRajan
Hi Rupal,
I tried yours also but same error. My Condition formula is:_
          AND(NOT( ISBLANK(AccountId) ),MailingPostalCode  <>  Account.ShippingPostalCode)

Error- Challenge Not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic
RajanRajan
Any one is there for help me for this error?
Wynnie AuWynnie Au

AND(NOT( ISBLANK( Account.Name) ),MailingPostalCode <> Account.ShippingPostalCode)
Neha KamraNeha Kamra
Yes. @Wynnie , This is perfect .

Thanks,
Gina DeCastro 9Gina DeCastro 9
Thanks Wynnie! I was stuck as well.
 
Ranjith SangatiRanjith Sangati
Hi,
Try this---

AND(
NOT(ISBLANK( AccountId )),
(MailingPostalCode <> Account.ShippingPostalCode )
)
narendran mohanannarendran mohanan
Question though: Is MailingPostalCode a sub element of "MailingAddress" field?
narendran mohanannarendran mohanan
Nevermind, I guess Address is a compound field and yes MailingPostalCode is part of address.
Richard HalfordRichard Halford
We leveraged the Account Name for the Account being blank.

AND (
NOT(ISBLANK( Account.Name )),
 MailingPostalCode !=Account.ShippingPostalCode)
Gina DeCastro 9Gina DeCastro 9
Thanks so much Richard. I will try that. Thank you, Gina De Castro, Salesforce Certified Professional Application Operations People Leader - Salesforce Farmers Insurance Cell: 302-668-4278 Gina.Decastro@farmersinsurance.com Upcoming PTO:
Suraj Tripathi 47Suraj Tripathi 47
Hi Rajan,

You can use the below one.
AND(
  NOT( ISBLANK( AccountId ) ),
  MailingPostalCode != Account.ShippingPostalCode
)

If you find your Solution then mark this as the best answer. 

Thank you!

Regards 
Suraj Tripathi