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
Roy MooreRoy Moore 

Stuck on Trailhead Challenge for Unit 3/3 Validation Formulas

Hey community,

I'm struggling with the logic of the task...

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 what I got so far:

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

I THINK I know how to see if the contact mailing zip is not the same as the account shipping zip, and only if the is not blank.

The part I am stuck on is if the "Contact records with no associated parent account can be added with any MaiilingPostalCode value"...

I don't know what to do with that.

Also, I am now getting the error message when I recheck challenge:

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: [] 


Double help, please.

Best Answer chosen by Roy Moore
Frédéric TrébuchetFrédéric Trébuchet
Hi,

Checking "NOT ISBLANK" for "AccountId" is enough for this challenge.
The import part is that you have to check only if the contact has an account: "A contact with a MailingPostalCode that has an account and does not match the associated Account ShippingPostalCode".
You don't have to check if "MailingPostalCode" is blank or not.
AND(
  NOT( ISBLANK( AccountId ) ),
  MailingPostalCode <> Account.ShippingPostalCode
)
Regards,
Fred
 

All Answers

BalajiRanganathanBalajiRanganathan
We need to check if contact has a account or not by NOT(ISBLANK(AccountId))

This should work 
AND( NOT(ISBLANK(AccountId)), NOT(ISBLANK(MailingPostalCode)),  MailingPostalCode  <>  Account.ShippingPostalCode )
Frédéric TrébuchetFrédéric Trébuchet
Hi,

Checking "NOT ISBLANK" for "AccountId" is enough for this challenge.
The import part is that you have to check only if the contact has an account: "A contact with a MailingPostalCode that has an account and does not match the associated Account ShippingPostalCode".
You don't have to check if "MailingPostalCode" is blank or not.
AND(
  NOT( ISBLANK( AccountId ) ),
  MailingPostalCode <> Account.ShippingPostalCode
)
Regards,
Fred
 
This was selected as the best answer
Frédéric TrébuchetFrédéric Trébuchet
Hi Roy,

Don't forget to mark this subject as Solved to help anyone if you're satisfied with the answers and encourage people with Like or Best answer tag ;)

Thanks
Fred
Roy MooreRoy Moore

Thanks, Fred.  That did the trick.  I misunderstood the task.  Appreciate the assist.

Roy

Ghulam Murtaza 5Ghulam Murtaza 5
for me same task got done with this particular formula.

AND( 
NOT( ISNULL( Id ) ), 
$Organization.PostalCode <> ShippingPostalCode 
)

bests,
murtaza
Kai RostcheckKai Rostcheck
Frédéric Trébuchet this worked perfectly, thanks!
@DBohrisch@DBohrisch
I was neglecting the NOT()... thank you :)
Puller Mayfield 5Puller Mayfield 5
Would this also work? Just curious:
OR( 
MailingPostalCode <> Account.ShippingPostalCode, 
ISBLANK( AccountId ) 
)
Lorenzo Montemayor 4Lorenzo Montemayor 4
Worked perfectly, thanks!
Jadden ResendizJadden Resendiz
I tried this and the trailhead challenge said "Challenge not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic" Did I input this incorrectly? I checked the syntax and got no errors. 

User-added image
 
Frédéric TrébuchetFrédéric Trébuchet
Hi Jadden,

The "not(isblank(MailingPostalCode))," is not part of the challenge.
Maybe the reason why your are nor successfull.

Hope this helps,
Fred

Joe Smith 12Joe Smith 12
Right on Fred!
 
Richard HardonRichard Hardon
Using Both variations in this thread 

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

Both versions give the same error
Error Message: 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 the associated Account ShippingPostalCode should return with a validation error: [MailingPostalCode]
 
Frédéric TrébuchetFrédéric Trébuchet
Hi Richard,

As said, I think the "not(isblank(MailingPostalCode))," is not part of the challenge.

Hope this helps,
Fred
 
gr33nj3110gr33nj3110
Are you kidding me?

None of the code I tried was working (always the same "here's what's wrong" message). I finally found this forum discussion. Again, I kept trying to use the code from "Best Answer chosen by Roy Moore" presented by "Frédéric Trébuchet" (I apologize for any of my "thumbs down" votes up there). My Trailhead Challenge would not complete still!

Exact same error (added some "*"s here for public display) every time:
------------------------
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, This is complete ********.: []

------------------------

I changed my "Description" (had been using it to save different versions of my code for reference) and "Error Message" (took out a swear word)... and suddenly the code that didn't work a minute ago... worked!

Did my Trailhead Challenge keep failling because I had saved some code in the "Description" field (it would be nice if SF supported "comments" in the coding area, especially for troubleshooting)... or... does SF have a "profanity check" somewhere? Ha, ha, ha!

 
Frédéric TrébuchetFrédéric Trébuchet
@jody_b: remove "__c" as you are working with standard fields, not custom fields
Frédéric TrébuchetFrédéric Trébuchet
@Darick Jackson: no problem for your "thumbs down" and apologize for mine ;)
jody_bjody_b
@Frédéric, thanks for the reply. I used the forumla builder to select the fields and it inserted the __c. Aren't ShippingPostalCode and MailingPostalCode custom fields? I didn't see them on the Account and Contact object so I added them. 
Julian AllenJulian Allen
@jody_b, the issue is that the question specifies that the API name is "MailingPostalCode" in one case however as you pointed out the fields don't exist so need to be created and their API names by default have an extension of "__c" as they are custom. To get through the challenge as suggested delete the extensions. If it hasn't been solved that should get you through. 
Frédéric TrébuchetFrédéric Trébuchet
@joby_b: sorry for the delay. ShippingAddress and BillingAddress are compound fields, that's the reason why you can't see BillingPostalCode, BillingStreet and so on when looking at the Account or Contact standard fields. However, you can manipulate these fields separately.
Refer to this page for more details https://developer.salesforce.com/docs/atlas.en-us.200.0.api.meta/api/compound_fields_address.htm.
Aditya KamdiAditya Kamdi
AND( 
MailingPostalCode <> Account.ShippingPostalCode, 
ISBLANK(  AccountId  ) 
)


And I am still getting the error message 
"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, new version: []"

I just can't figure out what is going wrong here 
Frédéric TREBUCHETFrédéric TREBUCHET
Hi Aditya,

Replace "isblank(...)" by "not (isblank(...))"
Tekuru システム管理Tekuru システム管理
Hi I am Japanese Salesforce Developer.

Do not mistook the "Contact" and "Contract" ?
pranil nimase 2pranil nimase 2
IF( ISBLANK(AccountId), ISBLANK( MailingPostalCode ), IF( MailingPostalCode <> Account.ShippingPostalCode , true, false) )
ToxtarToxtar
Problem that got me was the usage of the word "parent account" If parent was not included in the exercise I would have had it.  I was inserting Parent.Account.ID
Hrishikesh DeshmukhHrishikesh Deshmukh

Hello,

My rule is set up correctly and works as expected displaying the error I need but i have been unable to go ahed with the trailhead challenge because of the following 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.


Not sure why I am getting this error because I am able to create a new contact without any association to a Account. I do get a validation error when I create a new contact associated to a account but with a different MailingPostalCode.
Getting expected behaviour for the validation rule but the trailhead challenge is failing.

My Validation Rule:
User-added image

Any help is appreciated!

Thanks

Fnu SumitFnu Sumit
First create "MailingPostalCode" Custom field with text datatype for Contact Object. and use this logic.

AND(
NOT( ISBLANK(   AccountId  ) ),
  MailingPostalCode__c   <>  Account.ShippingPostalCode 
)
sandesh kulkarnisandesh kulkarni
Hi Sumit,
This works perfectly for me in trailhead challenge.
AND(NOT (ISBLANK( AccountId )),
MailingPostalCode <> Account.ShippingPostalCode
)
The issue here is AccountID should be Contact->AccountId and Not Contact->Account->AccountID.
I complete this challange with this change.
Regards,
Sandesh

 
mike franklin 10mike franklin 10
Hi Fred:

I completed the challenge with you logic.  However the logic I used technically worked when tested.  I am assuming that with formulas like these, it can be done in many ways.  I tested it on the Account.Name field and not the ID field as you did.  But when testing it worked right.

Mine:

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

Yours:

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

Is that the correct assumption?

Regards,

- Mike Franklin
RajanRajan
Hi,
I tried all methods and getting same error as below :-- 
*******Challenge Not yet complete... here's what's wrong: 
The validation rule failed to enforce the business logic*************

I tried:-
1) AND(
NOT( ISBLANK( AccountId ) ),
MailingPostalCode <> Account.ShippingPostalCode
)

2) IF( ISBLANK(AccountId), ISBLANK( MailingPostalCode ), IF( MailingPostalCode <> Account.ShippingPostalCode , true, false) )

3) OR( 
MailingPostalCode <> Account.ShippingPostalCode, 
ISBLANK( AccountId ) 
)

Plz help to solve this problem.
Jenn DwyerJenn Dwyer
Rajan, I think you're over complicating the formula:

NOT( ISBLANK( AccountId )) && 
MailingPostalCode <> Account.ShippingPostalCode
Lakshan MeeriyagallaLakshan Meeriyagalla
Thanks for the formula 
Tiffany VasquezTiffany Vasquez
I was still having problems after reading this. If anyone else is a knucklhead like me, you might need to be told directly. Do not make custom fields for this challenge. If you have, delete them. They will interfere. Just thought I'd share :)
priyanka narisettypriyanka narisetty
hi I am able to finish the challenge but if i enter different mailing and postal code record is saving didn't get error message.validation rule is not working
Caleb KuesterCaleb Kuester
Just as a note, instead of spelling-out "not," you can use the "!" operator from programming languages. 
Krishna RaviKrishna Ravi
IF (NOT (ISBLANK( AccountId )) && Account.ShippingPostalCode <>  MailingPostalCode, TRUE, FALSE)
Tara WinhofferTara Winhoffer
This may sound a little asinine, but if your having issues and you keep updating the rule and immediatly clicking "Check Challenge" in trailhead and still coming up with errors, make sure you are saving the rule each time and not simply checking syntax. This advice could have saved me 4 minutes of screaming at my screen. 
Victor BloiseVictor Bloise
I also noticed that if you use the API when inserting the field (even though will work) Trail won't accept it, so I had to remove __c from ShippingPostalCode and MailingPostalCode
Suresh Babu KattaSuresh Babu Katta
This below code worked for me
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode
)
:) Cheers :) :)
 
Timothy BensonTimothy Benson
Don't forget to check the Active box.  I'm not ready to admit how long I spent on this before having an A-Ha moment that I needed to do that.  [Insert facepalm emoji] 
Nilotpal RoyNilotpal Roy
Hi All,

Please create a validation rule in Customize>Contacts>Validation Rules

User-added image

Then use error condtion formula:-
AND(
  NOT( ISBLANK(  AccountId  ) ),
  MailingPostalCode <> Account.ShippingPostalCode
)
User-added image
Hope this will help.
Regards,
Nilotpal Roy
Lisa SouletLisa Soulet
Yes, this is the correct code to pass the challenge in Trailhead.
Sekhar Oleti 6Sekhar Oleti 6
This one worked for me, thanks!! 
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode)
Santhosh PLSanthosh PL
Hi, 
The question which I ask may be silly, but please do educate me.
In the answer given,
"AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode)".
Question: How do we know that we should take 'AccountID' as the field name (Where are these fields availbale for reference).
 
Nilotpal RoyNilotpal Roy
@Santhosh PL

Here is your answer go to Insert Filed>Contact>Account ID

User-added image

Regards,
Nilotpal Roy
Santhosh PLSanthosh PL
@Nilotpal Roy
Thank you.. :)
Mark Sepeta VIIIMark Sepeta VIII

@Frédéric Trébuchet

I tested Frédéric Trébuchet's answer ... Yes, it passes SFDC's Challenge, which is all fine and dandy ... HOWEVER, I am still able to create contact records regardless of whether the mailingpostalcode matches the Account's Shipping Postal code or NOT.

SO, if you want to pass the challenge, just use that validation formula.

However, if you are trying to actually implement this function in a production SFDC org, it does not work correctly for users.

Alex Valavanis 10Alex Valavanis 10
Hello,

Got an issue here as well?! Any help appreciated.

(I have a field "Account_type_c" in the account object) ?!

User-added image
Sushma JayakumaraSushma Jayakumara
This Validation Rule helped...

AND( NOT(ISBLANK(AccountId)), NOT(ISBLANK(MailingPostalCode)),  MailingPostalCode  <>  Account.ShippingPostalCode )
Bhavya Mehta 8Bhavya Mehta 8
User-added image

Rule working perfectly fine. Below is the rule created.
User-added image

Any help is appriciated!!
Luis Arcos 1Luis Arcos 1
The following works fine for me in the challenge:
  1. In Contact Object Create custom field called "MailingPostalCode" (text datatype)
  2. Crete Validation Rule in Contact Object with the following formula:
    1. AND(
      NOT( ISBLANK( AccountId ) ),
      MailingPostalCode__c <> Account.ShippingPostalCode
      )
Later you can validate the challenge.

Regards,
@Lu.
Swapnil Patne 4Swapnil Patne 4
@Luis Arcos 1 Strange that it requires a custom field but your formula worked for me. Thanks!
Josué PeixotoJosué Peixoto
This work very well

AND( 
NOT( ISBLANK( Id ) ), 
ShippingPostalCode <> ShippingPostalCode 
)
Yolanda McDonaldYolanda McDonald
While I understand the reasoning behind using "NOT(ISBLANK(AccountID)" instead of "NOT(ISBLANK(MailingPostalCode)", I think the reason that people are running into issues with this particular challenge is the way that the challenge was worded.  In particular this sentence: 

Contact records with no associated parent account can be added with any MailingPostalCode value. (Hint: you can use the ISBLANK function for this check).  

I don't know if it was worded this way to throw off the challenger, but I'd guess from the fact that multiple people are running into the same issue and making the same assumption, it's a safe bet. The author of the challenge used MailingPostalCode in the sentence and never illuded to the use of AccountID.  If it had been reworded to include the POSSIBILITY of using AccountID, I think there would be less confusion.  Perhaps, something like this:

Contact records with no associated parent account (AccountID) can be added with any Mailing Zip/Postal Code (MailingPostalCode) value. (Hint: you can use the ISBLANK function for this check).

After reading this forum thread, it makes perfect sense, but I still think re-wording the challenge would lessen confusion or at the very least give a the challenger another option to consider.
Kavita Badgujar 10Kavita Badgujar 10
Thanks. This worked for me. :)
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
)

 
The_London_ScottThe_London_Scott
I feel the formula that passes the challenge does not actually match the wording of the challenge.
"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."

I read this to mean that the scope of the validation is contacts which 1) have MailingPostCode populated and 2) have Account populated. That makes sense to me, since loads of contacts may lack MailingPostCode, if an org's configuration does not force population.

However a formula which scopes the validation to that set of contacts:
AND(
  NOT(
    ISBLANK( MailingPostalCode)
  ),
NOT(
    ISBLANK( AccountId)
  ),
MailingPostalCode <> Account.ShippingPostalCode
)

is rejected.

I've logged a Trailhead case but I'm amazed to find that this thread pointed out the discrepancy between a passing formula and behaviour in practice two years ago and this issue is still there.
vittoria raimondo 2vittoria raimondo 2
You'll be completing this challenge in your own personal Salesforce environment. Choose from the dropdown menu, then click Launch to get started. If you use Trailhead in a language other than English, set the language of your Trailhead Playground to English before you attempt this challenge. Want to find out more about using hands-on orgs for Trailhead learning? Check out the Trailhead Playground Management module.
YOUR CHALLENGE
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 saving of a new or updated 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 saved
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 ISBLANKfunction for this check)


Challenge not yet complete in My Trailhead Playground 1
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: [loan_amount__c]: [loan_amount__c]


Can someone please help me ? i tried all different options bu i still have the same problem.
I am looking forward to hear from you. 

Kindest regards
vittoria raimondo 2vittoria raimondo 2
I found the solution thanks. 
Basically we have to create the the mailing postal code  field for conatct  and shipping postal code for account without  selecting the require field. 
then the formula  should work. Please find the formula here below:

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



i hope this helped 
Ro PerezRo Perez
This works  for me :) 

AND( 
NOT( ISBLANK( Id ) ), 
ShippingPostalCode <> ShippingPostalCode 
)
Cohn VosdoganisCohn Vosdoganis
I initially created the ShippingPostalCode and MailingPostalCode but realised that these were available when selecting the formula. Apart from some network issues today (which confussed the testing process), I could only get this to work by using the following (as per posts)
AND( NOT(ISBLANK(AccountId)), NOT(ISBLANK(MailingPostalCode)),  MailingPostalCode  <>  Account.ShippingPostalCode )

I have since removed the fields created and used the ones supplied.
Thanks all for your posts - NEXT
Glenn Cionek 12Glenn Cionek 12
AND( 
NOT( ISBLANK( Id ) ), 
ShippingPostalCode <> ShippingPostalCode 
)
Cassie GeorgCassie Georg

This formula worked:  

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

 

I was getting this error even after creating the Shipping Postal Code under Account and Mailing Postal Code under Contact as @vittoria raimondo 2 suggested:

 

Challenge not yet complete in My Trailhead Playground 1
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: [loan_amount__c]: [loan_amount__c]

 

To fix it, I had to go to Loan Amount under Object Manager > Contact & deselect the "Required" check box under General Options.  Our architect advised this is a trailhead error as Loan Amount has nothing to do with the challenge.


Hope this helps someone who spent an hour trying to figure it out like I did :).


Thanks!

Jeff Telijeune 10Jeff Telijeune 10
I am not an expert, but I think the reason why it doesn't work for some people it's because they try to create that specific validation rule onaccount instead of Contact. It should be created on Contact.
Erin Prior 6Erin Prior 6
This helped me: (thank you!)

pranil nimase 2 wrote:

IF( ISBLANK(AccountId), ISBLANK( MailingPostalCode ), IF( MailingPostalCode <> Account.ShippingPostalCode , true, false) )

 
Suvendu MohapatraSuvendu Mohapatra
This Syntax helped me : 

AND (
Not (ISBLANK ( AccountId )),
 Mailingpostalcode__c  <>   Account.ShippingPostalCode 
)

Problems faced were because :
1. Contact_name was a required field. So we need to remove the required field. ( The Error message was not displaying anymore)
2. We need to create custom object Mailingpostalcode__c under contact object .For account object we need to use the existing Shipping Zip/Postal Code Field ( Error message of business validation did not display after this)


Hope this helps.

Thanks,
Suvendu
 
Murali Balakuntalam 1Murali Balakuntalam 1
Challenge not yet complete in My Trailhead Playground 5
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: [MailingPostalCode__c]: [MailingPostalCode__c]
Sridhar S 35Sridhar S 35
I have tried all the suggestions given in the above thread on the existing Validation Rule i have created, but still faced the same problem.
Then tried the simple and ultimate trick......   Deleted the existing Vaidation Rule and created a new one copied and pasted the same code i.e "AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode <> Account.ShippingPostalCode )"     
And......It worked for me :)  
Please try and check once if it works.....
 
Tushar Choudhary 4Tushar Choudhary 4
User-added image

AND(
NOT(ISBLANK( AccountId )),
MailingPostalCode <> Account.ShippingPostalCode 
)
Jeff Olsick 13Jeff Olsick 13
Super helpful!!
Ezinhotel TecchEzinhotel Tecch
Thank you all. I have tested this code with different validation.

1AND(
2  NOT(
3    ISBLANK( MailingPostalCode)
4  ),
5NOT(
6    ISBLANK( AccountId)
7  ),
8MailingPostalCode <> Account.ShippingPostalCode
9)
Deepika RahangdaleDeepika Rahangdale
 i got same error
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 saved
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 -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: [First_Name__c, Last_Name__c]: [First_Name__c, Last_Name__c]


Ans-AND (
NOT( ISBLANK( AccountId )),
MailingPostalCode <>  Account.ShippingPostalCode )
Jeffrey Wong 168Jeffrey Wong 168
Hi all, I created the below validation formula first:

AND(
NOT( ISBLANK( AccountName ) ),
(MailingPostalCode  <>  Account.ShippingPostalCode)
)
and tried creating a few new contacts and it worked as required, prompting errors if there is an associated account and postal code is different. But it did not passed the challenge becasuse the required formula is:
AND(
NOT( ISBLANK( AccountID ) ),
(MailingPostalCode  <>  Account.ShippingPostalCode)
)

I strongly believe that there are many ways to skin a cat and my formula should work and pass the challenge as well. As long as the formula includes any compulsory account's fields, such as Account ID, Account Name or Account Number etc, the validation formula should work as required.  What do you guys think?

Cheers,
Jeffrey
Ganesh Mohan RamachandranGanesh Mohan Ramachandran
Thanks. I tried Frédéric Trébuchet solution. It worked
Naveen gawandeNaveen gawande
None of the CODES are working for me.... :( ... Same Error every Time.

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: [Preferred_Contact_Method__c]: [Preferred_Contact_Method__c]....


Let me know if someone can help...has been so many days got stuck here.
Naveen gawandeNaveen gawande
Still Getting Same Msg.
Jeffrey Wong 168Jeffrey Wong 168
@ Naveen, you may want to start a new org or playground.
Shayar ShubhamShayar Shubham
Done. It helped in solving my issue. Thanks for this valuable information. It helped me in my customers domain sad love shayari (https://sadloveshayarihindi.in) . Now everything is fine, just want to thank you for that (https://sadloveshayarihindi.in)
Harshita Verma 17Harshita Verma 17
For people that keep getting an error, make sure that you are creating it in Objectmanager > CONTACTS instead of accounts
SOURAV DASGUPTASOURAV DASGUPTA
This was a little tricky, we should create Contact Validation Rule and rest is very easy to create the validation rule. And also one more important point Field should be Contact>Account ID not Contact>Account>Account ID. Hope this solves your issues.
Fernando TelloFernando Tello
this one works for me 
AND(
NOT( ISBLANK( Id ) ),
BillingPostalCode <> ShippingPostalCode
)
Ria FieldRia Field
Hi
validation rule in contacts with the formula as 
AND( NOT(ISBLANK(AccountId)), NOT(ISBLANK(MailingPostalCode)),  MailingPostalCode  <>  Account.ShippingPostalCode )

worked perfect for me

Thanks Fred
Mehjabeen KunnilMehjabeen Kunnil
Thanks @Cassie Georg, I was getting the same error as yours!!
Challenge not yet complete in My Trailhead Playground 1
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: [loan_amount__c]: [loan_amount__c]
 
"To fix it, I had to go to Loan Amount under Object Manager > Contact & deselect the "Required" check box under General Options.  Our architect advised this is a trailhead error as Loan Amount has nothing to do with the challenge."     This was suggested by @Cassie Georg.
 
tsworldtsworld
The challenge completed with the validation rule I provided but when I go to Contact page to test this I never get the validation error

and(
NOT( ISBLANK( AccountId ) ),
(MailingPostalCode = Account.ShippingPostalCode)
)
 
Syed Ahmed 859Syed Ahmed 859
Use this to validate 
AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode <> Account.ShippingPostalCode )

then refresh the page in your contacts and try again.
Cristian MateusCristian Mateus
thanks Fred, your answer work´s for me, in addition I made a dumb mistake, I tray to write my validation rule for  Account  Object, but you need to do with Contact object, that was my mistake.

Regards
Anastassiya MayerAnastassiya Mayer
Hello guys,
I'm trying to resolve this challenge on the third day in a row. I tried every possible combination but nothing works.
Please help me!
The challenge:
Create a Validation Rule
Create a validation rule that displays an error message and prevents a user from creating or updating a contact if two conditions are both true.
Create a validation rule:
Rule Name: Contact_must_be_in_Account_ZIP_Code
Operator: AND (return true if both conditions are true)
Define two error conditions:
The contact is associated with an account id
Hint: Use the ISBLANK and NOT functions.
The contact mailing zip code is different than the account shipping zip code
Hint: Use the API names (MailingPostalCode and ShippingPostalCode) and the <> (Not Equal) operator.
Enter an error message for the validation rule


My formula tries:
1:
AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode <> Account.ShippingPostalCode )
2:
AND( NOT( ISBLANK( Id ) ), MailingPostalCode <> Account.ShippingPostalCode )
3:
AND( NOT(ISBLANK(AccountId)), NOT(ISBLANK(MailingPostalCode)),  MailingPostalCode  <>  Account.ShippingPostalCode )\
4:
And almost every single query I found in this topic above.
I also tried to delete Validation Rule and create new one, I tried to refresh page but nothing is working ((((
This my error:
Challenge not yet complete in Cunning Koala Playground playground 2
Whoops, looks like there was a problem. Please try again.
Karissa GonzalezKarissa Gonzalez
I was getting the same error message over and over again even though I had the correct formula.
AND(
  NOT( ISBLANK( AccountId ) ),
  MailingPostalCode <> Account.ShippingPostalCode
)

I switched playgrounds, tried the formula again, and that's when it finally worked.
Hope this helps!
 
Neslihan DincerNeslihan Dincer
Hello,  I see many people have the same problem as me. In fact, my formula was true but when I click verify I got an error each time. I had been trying almost for 1 hour on the same challenge, and FINALLY, I found what my mistake was. I just was working on the ACCOUNTobject, and when I changed it to CONTACT the problem was solved. I just copied my same formula and it did work.
My formula was : AND( NOT( ISBLANK(  AccountId  ) ) ,   Account.ShippingPostalCode  <>  MailingPostalCode  )
hikmat ismayillihikmat ismayilli
((ShippingPostalCode <> Owner.Contact.MailingPostalCode) && NOT(ISBLANK(Name)))
 
Steve RoybalSteve Roybal
This challenge was horribly written. Thumbs down to whoever wrote the challenge. I didn't know what object/objects to set up the validation rule in. Thanks to Fnu Sumit for the solution:
User-added image
Keny PatidarKeny Patidar
Please help with code for below validaiton
Create a validation rule:
Rule Name: Contact_must_be_in_Account_ZIP_Code
Operator: AND (return true if both conditions are true)
Define the two conditions that, combined, will show the error message:
The contact is associated with an account id
The contact mailing zip code is different than the account shipping zip code
Hint: Use the API names (MailingPostalCode and Account.ShippingPostalCode) and the <> (Not Equal) operator.
Enter an error message for the validation rule

Using below code, but getting error:
AND(
NOT(ISBLANK( AccountId )),
MailingPostalCode <> Account.ShippingPostalCode
)
Osazeme UsenOsazeme Usen

The challenge was poorly worded. Use the Contact object instead of the Account

Your formula should look similar to what I have below and you'll be fine.

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