0

I'm new to salesforce and I'm doing the Trailhead problem about the validation ruels. This is che challenge:

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)

This is my validation rule:

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

It raises this error (I see it in the Trailhead pages):

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, Postal code not consistent in contact and account: []

Moreover, if I manually test it creating and updating Contact and Account records I can update records without errors but not insert records (the error always show and it seems that che rule NOT( isblank(AccountId ) ) is always true during the insert operation.

What's happening?

  • Hint: Review the details of exactly which fields you're specifying in your validation rules VERY closely when you run into these kinds of problems. – crmprogdev Feb 10 '15 at 14:39
  • Hi @crmprogdev first of all, taking apart the trailhead problem, I don't understand updates works and insert do not.. validation rules are called in both insert and updates, isn't it?? – mcmc Feb 12 '15 at 7:44
  • I suggest you follow the resource links provided in Trailhead to help you learn the material, particularly to (Help) About Validation Rules which answers your question. "Validation rules apply to new and updated records for an object" That means the rule needs to consider alternate conditions like IsNew() and PrevValue(), etc. – crmprogdev Feb 13 '15 at 18:19
  • @crmprogdev I know it is an old question but if you add it as answer I can accept it – mcmc Apr 22 '15 at 13:26
2

I suggest you follow the resource links provided in Trailhead to help you learn the material, particularly to (Help) About Validation Rules which answers your question. "Validation rules apply to new and updated records for an object." That means the rule needs to consider alternate conditions like IsNew() and PrevValue(), etc.

-2

try this:

(MailingPostalCode  <>  Account.ShippingPostalCode)  &&  NOT(ISBLANK(AccountId))
  • That's the same validation rule that OP said was not working. All you did was switch this AND() with this && – martin Jun 8 '17 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.