+ Start a Discussion
Rohit TripathiRohit Tripathi 

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

I am getting error message while solving this challenge in 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)

Error Message is :  There was an unhandled exception. Please reference ID: HKIZNLVZ. Error: Trailhead::TrailheadTimeOut. Message: Trailhead.view: failed to get a 200 response. Made 3 attempts each resulting in a 403 or 500 failure for url challenges?key=%5B%22trailhead.challenge.validation_rules.en.us.192%22%5D.

I am not sure what went wrong here.
My Validation Rule is on Contact Object  :

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

Can anyone please help with this.
Best Answer chosen by Rohit Tripathi
Amit Chaudhary 8Amit Chaudhary 8
Please try below valudation rule
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode
)
i Used same and got all points in Trailhead challenge


 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below valudation rule
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode
)
i Used same and got all points in Trailhead challenge


 
This was selected as the best answer
Rohit TripathiRohit Tripathi
Hi Amit,

It worked. I have few questions :

1) How did you come up with != operator
2) If you look Field dettails for Contact Object, Account field is of data type Lookup(Account). How did you come up with AccountID ?
 
Amit Chaudhary 8Amit Chaudhary 8
Hi Rohit,

1) According to validation rule we need to check if both are not equals same means !=.
2) On Contact we have account Lookup(Account) which API name is AccountId.

you Can check API name from below link:-
Account:-
https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_account.htm
Contact:-
https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_contact.htm
 
Rohit TripathiRohit Tripathi
Thanks Amit.

API link is not working. Do you have Navigation path ?
Sakthivel ThandavarayanSakthivel Thandavarayan
That's the correct link... you can refer the field names here,

https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_contact.htm

 
Shane MphaheleShane Mphahele
@Amit Chaudhary 8.. I used the same Formula but got an error, 

Challenge not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic.
User-added image
Amit Chaudhary 8Amit Chaudhary 8
Please try to use below code
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode
)

 
Shane MphaheleShane Mphahele
I just changed the operator to != , still got the same error
Shane MphaheleShane Mphahele
Not sure if trailhead is the problem or my DE org.  
:'(
Amit Chaudhary 8Amit Chaudhary 8
You can do one thing .
Step 1) Delete above validation rule and try again
Step 2) Try to login with some other DE org and try.

I hope this will help u
Shane MphaheleShane Mphahele
I did do as you said, unfortunately I am still not winning.
same error.
"Challenge not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic"
Shane MphaheleShane Mphahele
Finally it worked, but I had to close spaces!!! Thanks @Amit Chaudhary 8
User-added image
Crystal ZhuCrystal Zhu
I just finished the challenge.  Here is the Error Condition Formula:  ( Account.ShippingPostalCode <> MailingPostalCode) && NOT(ISBLANK (Account.Name)). If  "insert operator" was used, it was quite simple. Cheers,
Levi BohonLevi Bohon
AND( 
NOT(ISBLANK(Account.ShippingPostalCode)), 
MailingPostalCode <> Account.ShippingPostalCode)
Anil ShekharAnil Shekhar
Here is what worked for me ... 
Error condition formular: ((ShippingPostalCode <> Owner.Contact.MailingPostalCode) && NOT(ISBLANK(Name)))
Adeline MooreAdeline Moore
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: []
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)

Here is  a screen shot of my rule:

User-added image
Brianne Beatty 16Brianne Beatty 16
The problem with this code is that TrailHead accepted it as the correct code but it doesn't allow the contact associated with an Account .. So the TrailHead is flawed.
David OknerDavid Okner
Shouldn't the code be this:

AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode
 ||  MailingPostalCode !=  Account.BillingPostalCode 
)
To account for both billing and shipping addresses?
Srinivas A 17Srinivas A 17
@Adeline Moore:i too faced this issue but after deleting and re-creating the validation rule it was success.
Used code is :
AND(NOT(ISBLANK(AccountId)),MailingPostalCode != Account.ShippingPostalCode)

Query:
What is the differnce between these two operators <>and !=?
 
ashley brownashley brown
why was != used and not the supplied operator <>
Ishita Jain 7Ishita Jain 7
I am still getting the error as follows:

User-added image 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: Delete failed. First exception on row 0 with id 0033600000jXw2eAAC; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Account id is null. Cannot delete it: []
Amit Chaudhary 8Amit Chaudhary 8
It look like you created any Custom Validation or trigger due to that validation rule is executing. Please deactivate the same and try again
Sravan Varanasi 3Sravan Varanasi 3
When I was trying to solve this challenge, I was getting the following error.

User-added image

The rule I have written:
AND(NOT(ISBLANK(AccountId)),  Mailing_Postal_Code__c  !=  Account.Account_Shipping_Postal_Code__c)

However, when I changed the API name in the formula from "Shipping_Postal_Code__c" to "ShippingPostalCode" manually, I was able to pass the challenge.

I was hoping to understand the difference between both the naming conventions, because when I try to insert the field through the "insert field" button, it is inserting the API name with underscore by default.

Any help would be appreciated. Thanks!
Vaishali mehtaVaishali mehta
I am using the solution :

AND( 
NOT(ISBLANK(AccountId)), 
MailingPostalCode != Account.ShippingPostalCode)


But still getting this error :
Challenge Not yet complete... here's what's wrong: 
A contact with no parent account could not be inserted. The validation rule should only apply to contact records with an associated account.

Please help me out.
 
Amit Chaudhary 8Amit Chaudhary 8
Please check you have created any validation rule on contact object, If yes then please deactivate the same and try again
vamshidher reddyvamshidher reddy
Actual formula is,
AND( 
NOT(ISBLANK(Account.ShippingPostalCode)), 
MailingPostalCode <> Account.ShippingPostalCode)
Abhishek Puri 7Abhishek Puri 7
ISBLANK( MailingPostalCode ) && Account.ShippingPostalCode <> MailingPostalCode
shivam sharma 44shivam sharma 44
Challenge completed.Try with below
NOT(ISBLANK(AccountId))&& ( Account.ShippingPostalCode != MailingPostalCode )
Riddhesh PatelRiddhesh Patel
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: REQUIRED_FIELD_MISSING, Required fields are missing: [Contact_Name__c]: [Contact_Name__c]

This is the error I am getting. I used

NOT(ISBLANK(AccountId))&& ( Account.ShippingPostalCode != MailingPostalCode )

PLease help
Amit Chaudhary 8Amit Chaudhary 8
Look like you create a validation rule on Contact_Name__c field or you created Contact_Name__c field as required field.
If you created the validation rule then please deactivate the same or if field is required at field level then uncheck the required check box and try again
Amit Agrawal 90Amit Agrawal 90
Thanks Amit, this helped ...one more challenge completed 
md saif ansarimd saif ansari
100% Will Work This Code......Try This code you will get all points in trailhead.
AND( 
NOT(ISBLANK(AccountId)), 
MailingPostalCode = Account.ShippingPostalCode)
JRR TWOJRR TWO
Any hints for this error? All my Workflow Rules are deactivated:

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: CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30161000000QaNy. Flow error messages: An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.: []
Josh OverettJosh Overett
I kept getting errors despite using many different code versions copied from previous replies and removing and recreating the rule multiple times as well and also logging out and in to the playground as well. In the end I solved it by using an alternative sandbox/playground I had previously created and creating the same rule in there. Worked first time Challenge solved. I suspect it was a bug/glitch in the Trailhead - Playgournd checking system.
Amber SharmaAmber Sharma
The Below Code Works Well :)
AND( 
          NOT(ISBLANK(Account.Name)),
                OR(
                                ISBLANK(MailingPostalCode),
                                Account.ShippingPostalCode <> MailingPostalCode
                )
)

It is also applied when the MailingPostalCode field of Contact is blank.
Merlyn Manuel (Gomez)Merlyn Manuel (Gomez)
ISBLANK(  Owner.Address )  = ISBLANK(Account.ShippingPostalCode)

This worked for me.
Andrea DalsenoAndrea Dalseno

Also

NOT OR(
ISBLANK(  AccountId  ),  
MailingPostalCode = Account.ShippingPostalCode )
kora bornkora born
Of all the comments here, only ansari's worked - which doesn't make any sense, as he used an = instead of <>
(And the sad part here is, the motive is not to get all the trail points BUT to understand working with SFSC.)

The edit validation screen clearly says "If this formula expression is TRUE, display the text defined in the Error Message area"
So logically speaking, shouldn't it be: MailingPostalCode  <>  Account.ShippingPostalCode ??

 
Bernard Philipsen 6Bernard Philipsen 6
Hi all,

I've been getting an different kind of error before saving. With my syntax check i get "Field AccountId does not exist".  And after trying other solutions ( eg with account name which is a field showing in the picklist) as stated above i get the same in my DE org or my normal trailhead org. So i added a AccountId field, but i still get this syntax error.

Any suggestions?
kora bornkora born
Since it is a different error you should have opened another thread instead of posting here ?
Ilya IvanovskiyIlya Ivanovskiy
Create a validation rule to check that a contact is in the zip code of its account.
 
AND(
  NOT( ISBLANK( AccountId ) ),
  MailingPostalCode <> Account.ShippingPostalCode
)

If you get an error:
Error: Field AccountId does not exist. Check spelling.
This means that you are trying to create a rule in the account object.
The rule must be created in the contacts object.
Marileus BernardezMarileus Bernardez

11-18-18 updated formula

AND( 
NOT(ISBLANK(ShippingPostalCode)), 
BillingPostalCode <> ShippingPostalCode)

Ranajit DondRanajit Dond
User-added image
Ranajit DondRanajit Dond
tell me the formula
 
UDAYA TEJA PASUPULETIUDAYA TEJA PASUPULETI
first creater this 2 custom fields in Contact object

MailingPostalCode 
ShippingPostalCode

create validation rule on Custom object with name Contact must be in Account ZIP Code, then use the bleow code.


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


So, first, the "And ( )" is telling the system, "Make sure everything within these ( ) is true." For instance, "And (Table is Red; Table has four legs)" This will only find you tables that are red and with four legs; not tables that are red with three legs, or blue tables with four legs. Next is the actual formula within the "And ( )." "Not (ISBLANK(Account))," is telling the system that if "Account" "is blank (ISBLANK)," then don't worry about triggering. So if a contact has something listed under the "Account field," then it's good to go. Or, in English, "only trigger if the account within the contact field is not blank." The next line is the second part of the "And ( )" formula. MailingPostalCode is in reference to the contact's ZIP Code <> means "does not equal" Account.ShippingPostalCode is in reference to the account's shipping ZIP Code. Thus instead of using those words, let's use just what it means, "Contact's zip code" - "does not equal" - "Account zip code." Thus, in the end, this code is saying, "When contact has an account AND the contact's zip code is not equal to the account's zip code, THEN trigger this error." Let me know if you have any questions about any of that!
Deede Heard 7Deede Heard 7
I was also receiving an error when Trailhead was attempting to validate my work on this trail in my developer org.  I ended up figuring out that the issue had to do with the EDA Managed Package that I had previously installed.  I ended up inactivating the Trigger Handlers for Addresses and Accounts and the validation was successful.
Deepti Gupta 12Deepti Gupta 12
Hi Amit,

Can you please help me to understand the formula you have shared. I am still getting an error message and not able to find MailingPostalCode field.

Thanks in advance.
Vipal PatelVipal Patel
Thanks Amit Chaudhary,

This code helped me out :)

AND(
2NOT(ISBLANK(AccountId)),
3MailingPostalCode != Account.ShippingPostalCode
4)
Mohamadou DOUCOUREMohamadou DOUCOURE
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode <> Account.ShippingPostalCode
)
Yousuf ZamanYousuf Zaman
This worked for me.
AND( 
          NOT(ISBLANK(Account.Name)),
                OR(
                                ISBLANK(MailingPostalCode),
                                Account.ShippingPostalCode <> MailingPostalCode
                )
)

 
ankur jain 94ankur jain 94
Below code worked for me
AND(
NOT(ISBLANK(Account.Name)),
OR(
ISBLANK(MailingPostalCode),
Account.ShippingPostalCode <> MailingPostalCode
)
)
somebody above shared this code. Thanks!
Amarnath Reddy 46Amarnath Reddy 46
I was getting error like : ShippingPostalCode is not mapped to Account (something of that sought). i came here to check if the validation rule i implemented is correct (that's was ok). Then, i accidently happened to delete one of the Contact Objects..
So you need to you two Contact objects in obj  manager...
if you think you messed it then try to complete the challenge into developer edition.
workaround 1 > create in Dev Edition (OR)
workaround 2 > check if you have all data (shipping pos code under account), mailing post code & two contact objects. 
User-added image
Ulrich TIEFENGUlrich TIEFENG
User-added image
AND(
NOT(ISBLANK(Account.Name)),
OR(
ISBLANK(MailingPostalCode),
Account.ShippingPostalCode <> MailingPostalCode))