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
Dmitry DubnovitskyDmitry Dubnovitsky 

Create a validation rule to check that a contact is in the zip code of its account

I am working in https://developer.salesforce.com/trailhead/point_click_business_logic/validation_rules.I have following message in validate rule:"Challenge Not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic"
My examples:
1.NOT(ISBLANK(AccountId)) && Account.ShippingPostalCode != MailingPostalCode
2.AND( NOT(ISBLANK(AccountId)),
 MailingPostalCode != Account.ShippingPostalCode
 )
3.AND( NOT(ISBLANK(AccountId)),
 MailingPostalCode <> Account.ShippingPostalCode
 )
Help me please solve this problem!
Krishna SambarajuKrishna Sambaraju
The third one should work. It worked for me.
Dmitry DubnovitskyDmitry Dubnovitsky
Probably,it should work,but it  doesn't work for me.I don't know why.
Dmitry DubnovitskyDmitry Dubnovitsky
1.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: MailingPostalCode <> Account.ShippingPostalCode
2.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): NOT(ISBLANK(AccountId))
Dmitry DubnovitskyDmitry Dubnovitsky
User-added image
Krishna SambarajuKrishna Sambaraju
Hi Dmitry,

You should create a validation rule on contact, not a workflow rule. Please find the screenshot below.
Contact Validation Rule

Hope this helps.
Dmitry DubnovitskyDmitry Dubnovitsky
I  have already created validation rule on contact,but it doesn't work.
Krishna SambarajuKrishna Sambaraju
I don't if you have tried, re-creating the validation rule.
Inactivate / delete the workflow rule you have created, delete the validation rule and create the validation rule again from scratch. Make sure to use the naming convention as given in the trailhead challenge.

Check if that helps.
Anne WiegersmaAnne Wiegersma
I did it just now and solution number 3 worked for me.
validation

Contact -> validation rules.
Harini JeevanandamHarini Jeevanandam
Hi Dmitry, 

Did you get your problem solved? I put in the same rule and it gets saved without any syntax error and even it worked when I tried creating a contact with different ZIP code than its account ZIP. But in the Challenge it shows me "The validation rule failed to enforce the business logic" error! 

Anyone else faced this problem and solved it? Help! 

 
Md Dilowar HussainMd Dilowar Hussain
I am working on this trail as well and am getting the following error Please help me determine where I am going wrong:
Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, A contact with a MailingPostalCode that has an account and does not match: []

User-added image

Request for suggestions to overcome the above issue.
muqeet abdulmuqeet abdul

Hi Friends,

Use Create the Validation Rule in the Contact Field Steps to create validation rules for the above requirement is 

1) Setup | Bulid | Customize | Contacts | Fileds | Select Account Name | Click on Validation Rule | New.

2) Then Enter the Details
Rule Name:Contact must be in Account ZIP Code.                      
In Error Condition Formula: AND( NOT(ISBLANK(AccountId)),
                                            MailingPostalCode <> Account.ShippingPostalCode
                                            )
Error Message                     : Enter the error as per the requirement.

Error Location                      :Select the error location from the drop down menu Mailing Zip/Postal Code. 

3)Now Click Save
& Now Go & check in the traihead challage to check its working fine or not, Click check challenege.

Thanks
Muqeet