You need to sign in to do that
Don't have an account?
Create a validation rule to check that a contact is in the zip code of its account.
I am having a hard time figuring this one out. Your suggestions would greatly be appreciated.
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)
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)
Error Condition Formula:- MailingPostalCode <> Account.ShippingPostalCode && NOT( ISBLANK( AccountId ) )
Please mark the answer as Best Answer if you find it useful.
Thanks
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.
block the insertion of a contact:- it means you have to write a validation on Contact which will block insertion on a particular condition.
1. if the contact is related to an account:- this statement says Contact should not be inserted if it has an account i.e AccountId should not be null.
Formula:- NOT( ISBLANK( AccountId ) )
AND
2. has a mailing postal code (which has the API Name MailingPostalCode) different from the account's shipping postal code:- if MailingPostalCode of Contact is different from Account ShippingPostalCode
Formula:- MailingPostalCode <> Account.ShippingPostalCode
I hope the explaination will help you.
Let's take a Look at the problem and then solve it by breaking into smaller components:
- 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.
Contact may or may not have associated with the Account.Here we need to make sure that Contact has an associated Account.In other words,'Account Name' on the Contact object should not be blank.To check this conditon,Salesforce has provided 'ISBLANK' Function:ISBLANK(expression)
Checks whether an expression is blank and returns TRUE or FALSE
Account Name should be blank:
ISBLANK(Account.Name)
To make the above condition negative,we have 'NOT' Function:
Account Name should not be blank:
NOT(ISBLANK(Account.Name))
- 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.
Account's ShippingPostalCode should not match Contact's MailingPostalCode.Whenever this condition is true, we have to give an error to the user.Here we get our second part of the formula:
MailingPostalCode <> Account.ShippingPostalCode
Now,We need to throw a validation error,whenever these two conditions are true simultaneously.Here 'AND' Function comes very handy:
AND(logical1,logical2,...)
Checks whether all arguments are true and returns TRUE if all arguments are true
AND(
(NOT(ISBLANK(Account.Name))),
(MailingPostalCode <> Account.ShippingPostalCode)
)
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, shipping postal code has to be different: []
can someone tell me where do I begin to look. I entered this in the validation rule on the contact object:
AND(
(NOT(ISBLANK(Account.Name))),
(MailingPostalCode <> Account.ShippingPostalCode)
)
The validation rule failed to enforce the business logic" even though is use the formula "AND(
(NOT(ISBLANK( Account.Name ))),
( MailingPostalCode__c <> Account.ShippingPostalCode__c ) "
AND (
(NOT(ISBLANK(Account.Name))),
(MailingPostalCode <> Account.ShippingPostalCode)
)
NOT(ISBLANK(AccountId)),
MailingPostalCode !=Account.ShippingPostalCode)
William, please choose best answer and close this issue.
Thx
I've tried all of these solutions and none of them work.
Regards
AND(
(NOT(ISBLANK(Account.ShippingPostalCode))),
(NOT(MailingPostalCode = Account.ShippingPostalCode))
)
but maybe this would be wrong if : the Contact does have an Account, and that Account has a blank ShippingPostalCode. Since Name is required on the Account record, it seems better to use
AND(
(NOT(ISBLANK(Account.Name))),
(NOT(MailingPostalCode = Account.ShippingPostalCode))
)
But the suggestion by S.Arora worked for me too
AND(
(NOT(ISBLANK(AccountId))),
(NOT(MailingPostalCode = Account.ShippingPostalCode))
)
I prefer to use "Account.Name" because many (all?) objects have a required Name field, so, the technique is easy to remember.
AND( NOT( ISBLANK( AccountId ) ),
MailingPostalCode <> Account.ShippingPostalCode
However, when I go to 'test' it (I am going into an account record, such as "Edge Communications", zip of 78767, and adding a contact to the account), in BOTH cases I am getting the error, i.e. when I enter the zip 78767, or enter a random zip, the "Contact must be in Account ZIP Code" error comes up!
What is going on here? What is the code that will ACTUALLY block it.
Thanks
Please try the following code ,, it must work...
MailingPostalCode <> Account.ShippingPostalCode && NOT( ISBLANK( AccountId ) )
It worked perfectly.
Thanks