Trailhead - Formulas & Validations - How do I approach this exercise? - Answers - Salesforce Trailblazer Community
Ask Search:
Phyllis BiermannPhyllis Biermann 

Trailhead - Formulas & Validations - How do I approach this exercise?

I am working through the Trailhead - Formulas and Validations. I am on the last unit create validation rules and I need some guidance on how to approach the challenge in this section. I am fairly new to formulas and validations. I've a few simple ones working in my org, but I need to understand this better.

The challenge says.....
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 saving of a new or updated 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 saved
  • 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)
I would like some direction on which functions to choose to start, but I would prefer that you not give me the answer.  

Thanks
Best Answer chosen by Phyllis Biermann
Sunil SarillaSunil Sarilla
Hi Phyllis,
Since you don't want the full answer but directions

First, you need to check if a Contact has an associated Account
i.e. check if the Standard Account field is not blank
so you will need to use NOT and ISBLANK functions

then you will need the validation rule to fire when the Contact Maling Postal Code is not equal to Account Shipping Postal Code so you will need to use Not equal to function (<>)

then you will need to use AND function to combine both first and second rule for the validation rule to trigger

All Answers

Sunil SarillaSunil Sarilla
Hi Phyllis,
Since you don't want the full answer but directions

First, you need to check if a Contact has an associated Account
i.e. check if the Standard Account field is not blank
so you will need to use NOT and ISBLANK functions

then you will need the validation rule to fire when the Contact Maling Postal Code is not equal to Account Shipping Postal Code so you will need to use Not equal to function (<>)

then you will need to use AND function to combine both first and second rule for the validation rule to trigger
This was selected as the best answer
Phyllis BiermannPhyllis Biermann
Hi Sunil - thanks so much for the coaching!  That was exactly what I needed. 
After some trial and error with commas and parens, I managed to achieve no syntax errors. It worked in the trailhead dev site, and trailhead let me finish the module.

Once again, thanks for your support.
Phyllis
Frank "Tyler" RoblesFrank "Tyler" Robles
Hi Phyllis and Sunil! This is great information, however, I'm still having some trouble with this one and would like some further clues without the answer if possible.

When checking the syntax per instructions above, I get "Error: Syntax error. Extra AND". I used the NOT and ISBLANK formulas first then entered the mailing not equal to account shipping postal code afterwards. Am I entering these backwards? 
Phyllis BiermannPhyllis Biermann
Frank:
I will give you some additional hints and see where this takes you. If you need more help, then post again:)

Start with the expression And and put everything inside this. Pay attention to where you need a comma and closing the parenthesis.

Let me know if this helps.
Phyllis BiermannPhyllis Biermann
Perhaps post your validation equation here?
Frank "Tyler" RoblesFrank "Tyler" Robles
Hi Phyllis,

Your advice worked like a charm. Thanks for the help!