Validation rules in ValStorm allow you to enforce data integrity by preventing users (or automations) from saving records that don't meet your business criteria.
📋 How It Works
A validation rule uses the Formula Engine to evaluate a specific expression every time a record is created or updated.
- Trigger: Validation occurs during the record save process, after formula fields are calculated but before the data is committed to the database.
- Evaluation: The rule's expression is calculated.
- Outcome:
- If the expression returns TRUE: The validation passes, and the save continues.
- If the expression returns FALSE (or an error): The validation fails. The save is blocked, and the custom error message is displayed to the user.
🏗️ Components of a Rule
| Component | Description |
|---|---|
| Name | A human-readable label for the rule (e.g., "Minimum Age Requirement"). |
| API Name | A unique identifier used by the system. |
| Rule Expression | The formula that must evaluate to TRUE for the data to be valid. |
| Error Message | The message shown to the user if the rule fails. This can be a static string or a dynamic formula. |
💡 Best Practices
1. The "Pass" Condition
Always write your expression as the condition that makes the data valid.
- Correct:
{{record.amount}} > 0(The record is valid if amount is positive). - Incorrect:
{{record.amount}} < 0(This would block all positive amounts!).
2. Handle Blanks
Use ISBLANK() to ensure you aren't running calculations on missing data that might cause a rule to fail unexpectedly.
- Example:
IF(ISBLANK({{record.email}}), TRUE, CONTAINS({{record.email}}, "@"))
3. Descriptive Error Messages
Provide clear instructions on how to fix the error. Use dynamic formulas in error messages to show the user exactly what is wrong.
- Static: "The discount is too high."
- Dynamic:
'Discount of ' & {{record.discount_pct}} & '% exceeds the limit of 20%.'
🚀 Common Examples
Require a field based on another field
If the Lead Source is "Referral", the "Referred By" field must not be empty.
- Expression:
IF({{record.lead_source}} == 'Referral', NOT(ISBLANK({{record.referred_by}})), TRUE) - Error: "Referred By is required when Lead Source is Referral."
Prevent future dates
Ensure the "Birthdate" field is not set in the future.
- Expression:
{{record.birthdate}} <= TODAY() - Error: "Birthdate cannot be in the future."
Value ranges
Ensure a "Probability" field is between 0 and 100.
- Expression:
{{record.probability}} >= 0 && {{record.probability}} <= 100 - Error: "Probability must be between 0 and 100."
Pattern enforcement
Ensure a code starts with "ACT-".
- Expression:
LEFT({{record.account_code}}, 4) == "ACT-" - Error: "Account codes must start with the prefix 'ACT-'."
🛠️ Implementation via UI
- Navigate to the Object Builder.
- Select your Object.
- Click the Validation Rules tab in the sidebar.
- Click New Validation Rule.
- Use the Formula Editor (with autocompletion) to build your expression and error message.
- Click Save Validation Rule.