+ Start a Discussion
Arpit Jain92Arpit Jain92 

Validation Rule Problem

Hello Everyone,
I am stuck here...Please tell me how to create a validation rule for this and can anyone explain this question.

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).
1. Name the validation rule 'Contact must be in Account ZIP Code'.
2. 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.
3. 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)
Best Answer chosen by Arpit Jain92
logontokartiklogontokartik

Hi Arpit, the usecase is simple,

We are validating that any Contact created under an Account must have the same ZipCodes, obviously for data integrity and cleanliness.
To do this, we are preventing users from entering a zipcode that does not match Account's zipcode via Validation Rule.

The validation will be on Contact Object, and it checks if Contact Belongs to an Account first and then checks if zipcodes are matching. Something like below.
 
NOT(ISBLANK(AccountId)) &&  Account.ShippingPostalCode !=  MailingPostalCode

If you think that it should fire only if MailingPostalCode is populated you can do the below.
 
NOT(ISBLANK(MailingPostalCode)) && NOT(ISBLANK(AccountId)) && Account.ShippingPostalCode !=  MailingPostalCode


 

All Answers

Arunkumar RArunkumar R
Hi Arpit,

Here is the thing you need to do,

1. Create a validation rule named as 'Contact must be in Account ZIP Code' on Contact object.
2. Check if the contact object record is related to the account.
3. If Contact associated with Account, then check Contact "MailingPostalCode" with related Account "ShippingPostalCode".
4. If both are not matched, then you should throw an error.

 
KaranrajKaranraj
Arpit - Challenge is pretty straighforward. First you have to create validation rule with the name as mentioned in the first step.
Then in the formula editor just compare the contact mailling postal code and account shippingpostal code. They must be equal as per the challenge. In addition to that you have to check one more condition that Contact should be associate with the account record. You have to check
"AccountID is should be null and Contact mailing postal code = account shipping postal code"

Share what you have tired so far, it easy for us to guide you. Instead of posting direct answer of this challenge.
logontokartiklogontokartik

Hi Arpit, the usecase is simple,

We are validating that any Contact created under an Account must have the same ZipCodes, obviously for data integrity and cleanliness.
To do this, we are preventing users from entering a zipcode that does not match Account's zipcode via Validation Rule.

The validation will be on Contact Object, and it checks if Contact Belongs to an Account first and then checks if zipcodes are matching. Something like below.
 
NOT(ISBLANK(AccountId)) &&  Account.ShippingPostalCode !=  MailingPostalCode

If you think that it should fire only if MailingPostalCode is populated you can do the below.
 
NOT(ISBLANK(MailingPostalCode)) && NOT(ISBLANK(AccountId)) && Account.ShippingPostalCode !=  MailingPostalCode


 
This was selected as the best answer