+ Start a Discussion
ANAMIKA MONDAL 8ANAMIKA MONDAL 8 

Create a validation rule to check that a contact is in the zip code of its account _ error

Hii,

I'm trying to answera question on Trailhead, but it keeps giving me an error.

Question is like the below: 

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

The Error I'm getting :

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: REQUIRED_FIELD_MISSING, Required fields are missing: [MailingPostalCode__c]: [MailingPostalCode__c]


I've written the below V rule:

AND 

NOT(ISBLANK( AccountId )), 
MailingPostalCode__c != Account.ShippingPostalCode__c 
)

If the MailingPostalCode__c wasn't created, It won't allow me to create the V rule on contact with the field MailingPostalCode__c. And also how can the API name be only MailingPostalCode, its always gets concate with __c.
Please help me out.
Thank in advance.


 
NagendraNagendra (Salesforce Developers) 
Hi Anamika,

Please use the below validation rule which allowed me to pass the challenge successfully in my developer org.
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode != Account.ShippingPostalCode
)
For more information and queries on the above challenge please check with below link. Please mark this as solved if it's resolved so that it gets removed from unanswered queue which results in helping others who are encountering similar issue.

Regards,
Nagendra.
 
Anurag VermaAnurag Verma
Hi Anamika,

The field names "MailingPostalCode__c" and "ShippingPostalCode__c" that you are using are not correct. If you see in the challange they have mentioned the API names that you should be using: "MailingPostalCode" and "ShippingPostalCode".

After this change your code should work.
AND 

NOT(ISBLANK( AccountId )), 
MailingPostalCode != Account.ShippingPostalCode 
)
 
ANAMIKA MONDAL 8ANAMIKA MONDAL 8
Hi Nagendra/Anurag,
I've tried using the suggested V rule. Still its giving me the same 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: [MailingPostalCode__c]: [MailingPostalCode__c]".
sandesh kulkarnisandesh kulkarni
Hi Anurag,
 Correct formula for this is

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