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
Jeff SaboJeff Sabo 

Totally lost on validation rules

I am lost trying to create validation rules for the challenge in the one trailhead. The instructions mention the following:

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).

I have tried the following formulas and keep getting syntax errors"

API NAME MailingPostalCode
NOT (ISBLANK(API NAME SHIPPINGPOSTALCODE)

MAILINGPOSTALCODE
NOT (ISBLANK(SHIPPINGPOSTALCODE))

None of these have worked.

Can someone please help?
SandhyaSandhya (Salesforce Developers) 
Hi Jeff Sabo,

 "NOT ISBLANK" should be checked for "AccountId".
AND(
  NOT( ISBLANK( AccountId ) ),
  MailingPostalCode <> Account.ShippingPostalCode
)

The import part is that you have to check only if the contact has an account: "A contact with a MailingPostalCode that has an account and does not match the associated Account ShippingPostalCode."
You don't have to check if "MailingPostalCode" is blank or not.


Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya


 
Jeff SaboJeff Sabo
I tried your solution and it was still coming up with errors in the Syntax. Is there another step I am missing?

It is telling me that AccountId does not exist. Do I need to get an update scheduled to make this work?
Joaquin_teguiJoaquin_tegui
Hi Jeff,

Sandhya's formula works fine. Are you sure your creating this validation in the Contact Object? 
Jeff SaboJeff Sabo
I keep going to Customize, Accounts, and Fields. Is that the correct place to go?
Jeff SaboJeff Sabo
I did look elsehwere and I received a message stating I could not create a Roll Up Summary because it was not the master in a master-detail relationship
Joaquin_teguiJoaquin_tegui
For this challenge you're not doing a field but a Validation Rule. To do so go to Customize, Contacts, Validation Rules and click new and paste the code Sandhya send you.

A validation rule prevents users from saving incorrect data so in this case you have to create the validation on the contacts object since you're trying to stop the insertion of a contact.

Hope that explains it a little better. 
Amit Chaudhary 8Amit Chaudhary 8
Hi,

"MailingPostalCode" and "ShippingPostalCode" are salesforce standard field which will not visible to you on UI but that are there in address field
Please check below post to check Standard field Name

Account:-
https://help.salesforce.com/apex/HTViewHelpDoc?id=account_fields.htm&language=en (https://help.salesforce.com/apex/HTViewHelpDoc?id=account_fields.htm&language=en)

Contact:-
https://help.salesforce.com/apex/HTViewHelpDoc?id=contacts_fields.htm&language=en (https://help.salesforce.com/apex/HTViewHelpDoc?id=contacts_fields.htm&language=en)

Your validation rule on Contact should be like below
AND( 
NOT(ISBLANK(AccountId)), 
MailingPostalCode != Account.ShippingPostalCode 
)
User-added image

Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000BOHUIA4
2) https://developer.salesforce.com/forums/?id=906F0000000D7TZIA0
3) https://developer.salesforce.com/forums/?id=906F0000000BIQlIAO
4) https://developer.salesforce.com/forums/?id=906F0000000BR0HIAW

To Complete the CHALLENGE: you need to do below
Create a validation rule to check that a contact is in the zip code of its account.
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)

Means you need to check the contact MailingPostalCode  should be equals to Account ShippingPostalCode Address. And Make sure account should be blank.

So here we have two conditon . Account should not be blank and postal code should be same.

AND --------------------------------------> If you have two condition and both should be true then we should use And.
(
NOT(ISBLANK(AccountId)),-----------------------------------------------> ISBlank is used to check values is blank or not. NOT(ISBLANK()) means value should not be blank
MailingPostalCode != Account.ShippingPostalCode ------------> This line is checking account and contact postal code are same or nt
)

I hope this will help u

Let us know if thta will help you
SandhyaSandhya (Salesforce Developers) 
Hi Jeff,

I agree with Joaquin.challenge needs validation rule on contact.

Thanks and Regards
Sandhya