I feel silly posting this, but I cannot get the rule to work (I wish Salesforce had a step-by-step guide if you get stuck in a module!) Can someone help me code this validation rule:
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 ISBLANK function for this check)
답변 5개
Hi Melyssa,
This is probably the most infamous validation rule question posted on here haha.
You want to check that the Contact's Mailing Postal Code matches their Account's Shipping Postal Code if there is an associated Account with that Contact. That means you need to set up two conditions of this error:
1) Check if there is an Account with that Contact
2) Check that the Contact Mailing Postal Code matches Account Shipping Postal Code.For the first condition we can say:
NOT(ISBLANK(AccountId))
or
arguablyNOT(ISBLANK(Account.ShippingPostalCode))
The second condition we can say:
MailingPostalCode <> Account.ShippingPostalCode
Note, we need to check for both conditions, so we need to use an AND function and they both need to be true.
AND(condition1, condition2, ...)Your validation rule will look like this:
AND(
NOT(ISBLANK(AccountId)),
MailingPostalCode <> Account.ShippingPostalCode
)