You need to sign in to do that
Don't have an account?
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.
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. Regards,
Fred
All Answers
This should work
AND( NOT(ISBLANK(AccountId)), NOT(ISBLANK(MailingPostalCode)), MailingPostalCode <> Account.ShippingPostalCode )
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. Regards,
Fred
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
Thanks, Fred. That did the trick. I misunderstood the task. Appreciate the assist.
Roy
AND(
NOT( ISNULL( Id ) ),
$Organization.PostalCode <> ShippingPostalCode
)
bests,
murtaza
OR(
MailingPostalCode <> Account.ShippingPostalCode,
ISBLANK( AccountId )
)
The validation rule failed to enforce the business logic" Did I input this incorrectly? I checked the syntax and got no errors.
The "not(isblank(MailingPostalCode))," is not part of the challenge.
Maybe the reason why your are nor successfull.
Hope this helps,
Fred
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]
As said, I think the "not(isblank(MailingPostalCode))," is not part of the challenge.
Hope this helps,
Fred
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!
Refer to this page for more details https://developer.salesforce.com/docs/atlas.en-us.200.0.api.meta/api/compound_fields_address.htm.
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
Replace "isblank(...)" by "not (isblank(...))"
Do not mistook the "Contact" and "Contract" ?
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:
![User-added image](/forums/servlet/rtaImage?eid=907F0000000kFe8&feoid=Body&refid=0EMF0000000kE7b)
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:
Any help is appreciated!
Thanks
AND(
NOT( ISBLANK( AccountId ) ),
MailingPostalCode__c <> Account.ShippingPostalCode
)
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
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
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.
NOT( ISBLANK( AccountId )) &&
MailingPostalCode <> Account.ShippingPostalCode
Please create a validation rule in Customize>Contacts>Validation Rules
Then use error condtion formula:-
Hope this will help.
Regards,
Nilotpal Roy
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode)
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).
Here is your answer go to Insert Filed>Contact>Account ID
Regards,
Nilotpal Roy
Thank you.. :)
@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.
Got an issue here as well?! Any help appreciated.
(I have a field "Account_type_c" in the account object) ?!
AND( NOT(ISBLANK(AccountId)), NOT(ISBLANK(MailingPostalCode)), MailingPostalCode <> Account.ShippingPostalCode )
Rule working perfectly fine. Below is the rule created.
Any help is appriciated!!
- In Contact Object Create custom field called "MailingPostalCode" (text datatype)
- Crete Validation Rule in Contact Object with the following formula:
-
Later you can validate the challenge.Regards,
@Lu.
AND(
NOT( ISBLANK( Id ) ),
ShippingPostalCode <> ShippingPostalCode
)
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.
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:
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.
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
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
AND(
NOT( ISBLANK( Id ) ),
ShippingPostalCode <> ShippingPostalCode
)
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
NOT( ISBLANK( Id ) ),
ShippingPostalCode <> ShippingPostalCode
)
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!
pranil nimase 2 wrote:
IF( ISBLANK(AccountId), ISBLANK( MailingPostalCode ), IF( MailingPostalCode <> Account.ShippingPostalCode , true, false) )
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
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]
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.....
AND(
NOT(ISBLANK( AccountId )),
MailingPostalCode <> Account.ShippingPostalCode
)
1AND(
2 NOT(
3 ISBLANK( MailingPostalCode)
4 ),
5NOT(
6 ISBLANK( AccountId)
7 ),
8MailingPostalCode <> Account.ShippingPostalCode
9)
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 )
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
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.
validation rule in contacts with the formula as
AND( NOT(ISBLANK(AccountId)), NOT(ISBLANK(MailingPostalCode)), MailingPostalCode <> Account.ShippingPostalCode )
worked perfect for me
Thanks Fred
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.
and(
NOT( ISBLANK( AccountId ) ),
(MailingPostalCode = Account.ShippingPostalCode)
)
AND( NOT( ISBLANK( AccountId ) ), MailingPostalCode <> Account.ShippingPostalCode )
then refresh the page in your contacts and try again.
Regards
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.
I switched playgrounds, tried the formula again, and that's when it finally worked.
Hope this helps!
My formula was : AND( NOT( ISBLANK( AccountId ) ) , Account.ShippingPostalCode <> MailingPostalCode )
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
)
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 )