+ Start a Discussion
Gaurav Jain 144Gaurav Jain 144 

Please help with creating a Validation rule.

A scenario on Trailhead:
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)

How to do it..as i tried multiple ways..i am surely missing on something. Please help
                  
sfdcMonkey.comsfdcMonkey.com
hi Gaurav
try this onces
AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode <> Account.ShippingPostalCode )

Thanks
Gaurav Jain 113Gaurav Jain 113
Hey piyush..I had the almost same..instead i used Account.Name..error is"validation rule fail to enforce the business logic"
the same error coming with Account Id
Gaurav Jain 113Gaurav Jain 113
Piyush, it worked. apprently had to refresh..
Also clear why to use AccountId and not Account name.
Thanks a lot.
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Try this
AND( 
ISNEW(), 
NOT(ISBLANK( AccountId )), 
MailingPostalCode != Account.ShippingPostalCode 
)
sfdcMonkey.comsfdcMonkey.com
yes Gaurav its a good question why we use accountId insted of account.Name
In Salesforce, any contact object that is associated with an account object will have that account name and ID stored within it.
its show Account Name but actually it's used accountId field for it so we use AccountId here insted of accountName in our formula
I hop it's helps you
Thanks
Mark it best Answer if it helps you so it make proper solution for others :)