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
mike franklin 10mike franklin 10 

Creating Validation Rules - Challenge Question - Validation of Formula

Hello:

I am going through the trailhead in the following area:
  • Admin Intermediate
  • Formulas and Validations
  • Creating Validation Rules
I have completed the reading and created the validation rule.  

Formulas can be created in many different ways.  However based on the work instructions, I created the formula as this:

Challenge Exercise Question:

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)
My Answer

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

User-added image
I tested it using the following cases:
  • Created a contact, linked it to an account (with a postal code), duplicated the postal code value in the required field in the contact object
    • The result:  The contact record was not allowed to be added and the message error appeared
  • Created a contact, did not link it to an account, created the contact and added a postal value in the required field
    • The result: The contact record was allowed to be created
Based on the testng, the formula works as indicated.  Can someone validate this or can I be pointed out what I did incorrectly.

Regards,

- Mike
Dhanya NDhanya N
Hi Mike,

Instead of ISBLANK(Account.Name) = FALSE, check NOT(ISBLANK(Account.Name)). Then you may complete the challenge.

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

Thanks,
Dhanya
mike franklin 10mike franklin 10
Hi Dhanya: Thank you for your response. I went to retest the scenarios with both my formula and the one you provided to see if the results were the same as listed below. Both formulas worked in exactly the same way when tested. Thanks for providing the one they needed, or I would have been going in circles on that one. ? Regards, - Mike Franklin Michael Franklin | Consultant/Partner | MLA - MyLoadAdvisor Inc | 604-240-6434 | Twitter | Google+ ?
mike franklin 10mike franklin 10
Hi Dhanya:

I am actually getting an error regarding the business logic on both formulas.  The error message states that the "The validation rule failed to enforce the business logic."

The business rules that need to be enforced are:
  • 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.
  • API names:  MailingPostalCode, ShippingPostalCode

This is what is used in the formula correct?  I think the business rules are being enforced correctly, so I do not understand why I can not pass the trail correctly.  Am I interpreting the business logic incorrectly?

Regards,

- Mike Franklin

 
Ranga WickramadaraRanga Wickramadara
I am facing the same problem and cant get pass this module..... 
Any help is much appreciated.
Nick BoenziNick Boenzi
Validation Formula blocks the rule if the formula is TRUE.
AND checks everyline in the formula to be true.

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

If the account is NOT blank AND if the account zip is NOT blank and the Account zip and contact zip are different then call a validation block. Block because the account needs to have a zip and the zip must be the same as the contact or the contact record will not be saved to the related account object.
Suraj Tripathi 47Suraj Tripathi 47
Hi mike,

You can try the below validation rule, it will help you to complete your challenge.
AND( 
NOT(ISBLANK(AccountId)), 
MailingPostalCode != Account.ShippingPostalCode 
)

If you find your Solution then mark this as the best answer. 

Thank you!

Regards 
Suraj Tripathi
Garen LemosGaren Lemos
Hello All,

I just wanted to update the info in case anyone else is struggling with this module "Create Validation Rules" currently.
I had to use a mixture of what was listed above and what the module is currently asking for. The validation rule I used to complete the challenge was:

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

The module recommends using ShippingPostalCode, but I recieved an error message stating that this was mispelled. Only by using Account.ShippingPostalCode did it finally accept the answer. I hope this helps :)

Best,
Garen