Sunday 15 December 2013

Salesforce: Validation Rules

Validation rules verify the data entered into fields is of the correct data type and meets the standards you set before a record can be saved.

You can use boolean formulas that evaluates the field data and results in true/false statements.


You also have to specify an error message if the user breaks a validation rule on save due to an invalid value.


Salesforce processes rules in the following order:

  1. Validation rules
  2. Assignment rules
  3. Auto-response rules
  4. Workflow rules (with workflow actions)
  5. Escalation rules

Also:
  • When one validation rule fails, Salesforce continues to check any additional validation rules on that field or any other field on the page and displays all appropriate error messages at once.
  • If validation rules exist for activities and you create an activity during lead conversion, the lead converts but a task isn’t created.
  • Validation rules are only enforced during lead conversion if validation and triggers for lead conversion are enabled in your organization.
  • Campaign hierarchies ignore validation rules.
  • Salesforce runs validation rules before creating records submitted via Web-to-Lead and Web-to-Case, and only creates records that have valid values.
  • Validation rules continue to run on individual records if the owner is changed. If the Mass Transfer tool is used to change the ownership of multiple records, however, validation rules won’t run on those records.

How to create a validation rule:

  1. Navigate to the relevant object, field, campaign member, or case milestone.
  2. In the Validation Rules related list, click New.
  3. Enter the properties of your validation rule.
  4. To check your formula for errors, click Check Syntax.
  5. Click Save to finish or Save & New to create additional validation rules.

Example Validations:


Validates that the account Billing Zip/Postal Code is in the correct format if Billing Country is Canada.
AND(OR(BillingCountry = "CAN", BillingCountry = "CA", BillingCountry = "Canada"),
NOT(REGEX(BillingPostalCode, "((?i)[ABCEGHJKLMNPRSTVXY]\\d[A-Z]?\\s?\\d[A-Z]\\d)?"))
)

Validates that the account Billing Zip/Postal Code is valid by looking up the first five characters of the value in a custom object called Zip_Code__c that contains a record for every valid zip code in the US. If the zip code is not found in the Zip_Code__c object, or the Billing State does not match the corresponding State_Code__c in the Zip_Code__c object, an error is displayed.

VLOOKUP(
$ObjectType.Zip_Code__c.Fields.City__c ,
$ObjectType.Zip_Code__c.Fields.Name ,
LEFT(BillingPostalCode,5)) <> BillingCity

Validates that the account Billing Zip/Postal Code is in 99999 or 99999-9999 format if Billing Country is USA or US.AND(
OR(BillingCountry = "USA", BillingCountry = "US"),
NOT(REGEX(BillingPostalCode, "\\d{5}(-\\d{4})?"))
)

Validates that the Account Number is numeric if not blank. AND(
   ISBLANK(AccountNumber),
   NOT(ISNUMBER(AccountNumber))
)

Validates that the Account Number is exactly seven digits (if it is not blank). The number seven is simply illustrative.AND(
   ISBLANK(AccountNumber),
   LEN(AccountNumber) <> 7
)

Validates that a custom field called Hours Worked is not a negative number
Hours_Worked__c < 0Validates that the contact Mailing StreetMailing City, and Mailing Country are provided.OR(   ISBLANK( MailingStreet ),
   ISBLANK( MailingCity ),
   ISBLANK( MailingCountry )
)

Validates that the value of a custom date field is a weekday (not Saturday or Sunday).
CASE(MOD( My_Date__c - DATE(1900, 1, 7), 7),
0, 0,
6, 0,
1) = 0






No comments:

Post a Comment