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
mattytreksmattytreks 

Error on Trailhead when checking 'Creating Validation Rules' challenge

Hi All- as part of the challenge on the 'Creating Validation Rules' module, I created the following Validation Rule on the Contact Object, and confirmed that it indeed is working by creating a few test records.

However when clicking the 'Check Challenge' button, I get the following error.  Any ideas on how to resolve?

Validation Rule:
AND 
( NOT(ISBLANK(MailingPostalCode)), 
NOT(MailingPostalCode = Account.ShippingPostalCode) )
Error:
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, Zip Code must match that of the Account. Please correct and save.: [MailingPostalCode]
Thank you in advance for any assistance!
 
Best Answer chosen by mattytreks
William TranWilliam Tran
Your logic looks a little off:

Requirement: 
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)

Full Logic:

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


As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.

Thanks

All Answers

William TranWilliam Tran
Your logic looks a little off:

Requirement: 
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)

Full Logic:

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


As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.

Thanks
This was selected as the best answer
mattytreksmattytreks
Thank you, William.  I see exactly what you did there, and why my validation was off a little!
Bhavesh SharmaBhavesh Sharma
Thanks @William Tran , now i understood what was going wrong with my rule. Great explanation!!

My rule :
AND( 
ISBLANK(Account.Name), // this was incorrect as the challenge was to check if the Account field on a contact is "NOT" blank or not associated //to an account
MailingPostalCode =Account.ShippingPostalCode) // instead of the "!=" i was using "="