Stuck on 'create validation rules' challenge - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Emma FayEmma Fay 

Stuck on 'create validation rules' challenge

I'm working on the Admin Intermediate 'Create Validation Rules' challenge. https://trailhead.salesforce.com/content/learn/modules/point_click_business_logic/validation_rules?trail_id=force_com_admin_intermediate

This is the challenge:
- 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 ISBLANKfunction for this check)

I'm presuming that to check whether the postal codes are the same you use "MailingPostalCode  =  Account.ShippingPostalCode"

It's the third step which is confusing me. So far my best guess is this, but I know it's wrong:
IF(ISBLANK(Account.ParentId) MailingPostalCode, MailingPostalCode  =  Account.ShippingPostalCode)

I basically want to say - if the field is blank, take no action. If it's not blank, check whether they're the same. If they're not the same, don't allow the record to be saved.

​​​​​​​Help!
 
Best Answer chosen by Jayson (salesforce.com) 
Andrew CookAndrew Cook
Hi Emma,

I used the following and it worked:

AND( 
NOT( ISBLANK ( Account.Id ) ), 
MailingPostalCode <> Account.ShippingPostalCode 
)

All Answers

Andrew CookAndrew Cook
Hi Emma,

I used the following and it worked:

AND( 
NOT( ISBLANK ( Account.Id ) ), 
MailingPostalCode <> Account.ShippingPostalCode 
)
This was selected as the best answer
Emma FayEmma Fay
Perfect - that makes total sense. I just didn't know the AND function. Thank you!
Andrew CookAndrew Cook
No worries Emma glad it makes sense now.
karthik pullurikarthik pulluri
'create validation rules' challenge
Validation Rule Detail 
Rule NameContact_must_be_in_Account_ZIP_CodeActive
Error Condition Formula
AND(
NOT( ISBLANK ( Id ) ),
BillingPostalCode <> ShippingPostalCode
)
Heather WendelHeather Wendel
I struggled with this one as well but figured it out and wanted to share:. 

RULE NAME:
Contact_must_be_in_Account_ZIP_Code

ERROR CONDITION FORMULA: 
NOT( ISBLANK( AccountId ) ) 
 && 
 Account.ShippingPostalCode <>  MailingPostalCode

ERROR MESSAGE: 
MailingPostalCode does not match the associated Account ShippingPostalCode