+ Start a Discussion
Rachel_NatikRachel_Natik 

Trailhead Validation Rule Challenge Error

Hello,

I created the validation rule and checked that it worked in my org.
When I check it through trailhead, I get this 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 does not match Account Shipping Zip Code: []

A different thread suggested deactivating the rule but when I do so I get this:
Challenge not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic


For reference, this is the validation rule.
(NOT (ISBLANK(Account.Name))) && (MailingPostalCode <> Account.ShippingPostalCode)
Looks good and works well. 

Any thought?
SFDC@RnSFDC@Rn
Try this one. .basically the same... but might be with the syntax notation..
AND((MailingPostalCode <>  Account.ShippingPostalCode),
NOT(ISBLANK(Account.ShippingPostalCode)))
Rachel_NatikRachel_Natik
Nope, didnt work either although the validation rule does fire. I got the same error. And then another error to say that it doesnt do what is asked, I think its a problem with how trailhead is verifying the challenge.
Sakthivel ThandavarayanSakthivel Thandavarayan
I have completed it without issues. Need one more logical check --> Validation rule should restrict only new contacts ! 
arvind bhandari 8arvind bhandari 8
I have creted this and its working fine 
AND((MailingPostalCode <> Account.ShippingPostalCode), NOT(ISBLANK( Account.Name )))
Rachel_NatikRachel_Natik
All those triggers did the job but werent being accepted by trailhead. Someone brought it to my attention thats its ONLY for NEW contacts so I added ISNEW() Now waiting for trailhead to work to verify :-)
arvind bhandari 8arvind bhandari 8
okz ...keep us updated
Rachel_NatikRachel_Natik
Just verified it!
Sakthivel ThandavarayanSakthivel Thandavarayan
Is it because of IsNew() or some other issue ? I'm not sure if its mandaory or not ! coz arvind got it working without that criteria !
Rachel_NatikRachel_Natik
You need that criteria because you only want it to validate when INSERTING contacts. Not editing.
Sakthivel ThandavarayanSakthivel Thandavarayan
yes, thanks. 
Jeffrey BehnkeJeffrey Behnke
I am strugging with this one also. Where do you put the ISNEW() clause?
Roger PavelleRoger Pavelle
I was able to use the version posted by arvind bhandari 8 without the ISNEW() clause.  My biggest confusion was that the directions referenced the account parent, so I was using Account.ParentID instead of Account.Name.
Rachel_NatikRachel_Natik
@Roger, did you pass the challenge?
Roger PavelleRoger Pavelle
Yes, I was able to pass finally, but am still confused when parent refers to ParentID and when it refers to something else.
Rachel_NatikRachel_Natik
What formula did you use? Just interested to know since I tried it about 6 different ways and it only worked with the ISNEW()
Roger PavelleRoger Pavelle
I used the one referenced above that was posted by arvind bhandari 8:
AND((MailingPostalCode <> Account.ShippingPostalCode), NOT(ISBLANK( Account.Name )))

The difference I see between this one and the one you posted in your original email is that it uses the AND function rather than the conditional &&.  Logically, I don't know why it would matter, but it must be something in the challenge vallidation logic.
Rachel_NatikRachel_Natik
Interesting, I tried both ways and didn't work. I think there was an error with the connection as well at the same time.
VJKVJK
I used the traditional nested IF statements and passed the challenge.
IF(ISBLANK( Account.Id ), false, (IF(MailingPostalCode  <>  Account.ShippingPostalCode, true, false)))

Any advantage of using AND() functions over nested IFs?
Dr. Thomas MillerDr. Thomas Miller
I passed the challenge some months ago - and now, without any changes, a Retake didn't pass. So I guess that this is not related to the formula you are using but some internal problems on trailhead side.
Dr. Thomas MillerDr. Thomas Miller
Setting up a new dev org helped - identical config.
Tavva Sai KrishnaTavva Sai Krishna
Can you please close this question by marking a best answer.

Thanks 
Sai Krishna tavva
ankurmarwah08ankurmarwah08
AND((MailingPostalCode <> Account.ShippingPostalCode), NOT(ISBLANK( Account.Name )))
 best working anwser
Phillip FrontPhillip Front
Weird, the correct formula STILL wasn't working for me, so I figured it must have been a trigger or process interacting with Salesforce's "challenge complete" verification in an unpredictable way. I just created a new Developer Org, connected that to my existing Trailhead account, and passed the challenge with flying colors! 
GhulamGhulam
Hi everyone, validation rule is working and fine to pass challenge, see below
AND( NOT(ISBLANK( Account.Name )) , MailingPostalCode <> Account.ShippingPostalCode )
GhulamGhulam
Hi everyone, validation rule is working and fine to pass challenge, see below
AND( NOT(ISBLANK( Account.Name )) , MailingPostalCode <> Account.ShippingPostalCode )
Bill Powell - CSS IncBill Powell - CSS Inc

I used Arvind's answer above and it worked fine: 

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

I'm trying to understand the difference between his answer any my original one which syntatically was fine, but Trailhead wouldnt approve it:

MailingPostalCode <> Account.ShippingPostalCode
&&
ISBlank(Account.Name)

Maybe i'm misunderstanding but NOT(ISBLANK(Account.Name)), when I translate this, ISBLANK(Account.Name) will be TRUE to fire, then the the NOT is saying its not true, meaning its not blank? So if that's truly the case, this is only going to fire when something is filled in, which wasn't the challenge? I would think ISBlank(Account.Name) would cause it to fire. Maybe i'm understanding it incorrectly. 

I got it right now, so thats good, but looking to improve my knowledge a bit. Thanks! 



 

Deb_GearsCRMDeb_GearsCRM
After trying all sorts of syntax and still getting the 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, Contact must be in Account ZIP Code: []

I created a new dev org and passed the challenge the first time with this rule:

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

So, if you have a proper validation rule that works when you create a new contact but gives an error in Trailhead, I would suggest creating a fresh dev org.  
 
Anvit SaxenaAnvit Saxena
I'm using this below code but still getting the error of "The validation rule failed to enforce the business logic"

AND( 
    NOT( ISBLANK( Account.Id ) ),   
   ShippingPostalCode__c  <>  MailingPostalCode__c 
)

he check syntax is passing with no errors but challenge is not getting completed. Can anyone suggest what should be done? Just to mention Im going to Setup->Opportunities and creating a new Validation Rule. 
Deb_GearsCRMDeb_GearsCRM
Anvit,  

1.  The fields are system fields, not custom fields so they shouldn't have the "__c" on the end.  

2.  The rule should be on the Contact object.  

This rule works:  
AND( 
NOT(ISBLANK(Account.Id)), 
MailingPostalCode != Account.ShippingPostalCode 
)

If you use this rule and still get error, create a new dev org. 
Anna Khardina-Vaisman 2Anna Khardina-Vaisman 2
Here is my version and it's working fine:

AND( 
ISNEW(), 
NOT(ISBLANK ( AccountId )), 
MailingPostalCode <> Account.ShippingPostalCode 
)
kapil arora 34kapil arora 34
Well, it's little tricky the way I see this. 

1) The formula works perfectly fine when I try to validate it by myself(not by trail challenge), trying creating or editing contact records. And I have __c at the end of the fields MailingPostalCode__c and ShippingPostalCode__c, but it fails trailhead challenge validation.

2) If I remove __c from the formula(no syntax error occur when you do this) the formula doesn't work when try to edit/create contact records. But the treailhead challange goes fine, why? because the business condition was to provide API name as MailingPostalCode and ShippingPostalCode i.e. without underscores. 
The question remains , is it possible to create your own API name(without __c) to get the balance on both the sides, i.e. a working validation rule and a successful challenge completion. All the best everyone.

Thanks,
Kaps
Ashish_TiwariAshish_Tiwari
Hope this solution will help you all who are facing in this trailhead-

Go To Setup- 
Customize-
Contact-
Validation Rules-
Rule name- Contact must be in Account ZIP Code- 

Formula-
AND(NOT(ISBLANK(AccountId)) ,MailingPostalCode <> Account.ShippingpostalCode)

Error Message- Zip Codes do not match-

Save

Its done check your Result in your trailhead page...

Contact Validation Rule task

Please do like if you found this helpful......
IAKSIAKS
Hi can anyone please help me, I am trying to understand why the value is NOT(ISBLANK(AccountId) shouldnt it be just ISBLANK (AccountID) because we are looking at the contacts that are linked with the accounts.
Shruthi141414Shruthi141414
Deb_GearsCRM's solution helped. It worked.