Setting Up Validation Rules
Administrators can configure validation rules to ensure information entered into fields are correctly formatted. A validation rule contains a formula that the entered information is tested against. If the formula results with a true value, a validation error message will appear, preventing the record from being saved.
Before You Begin
Requirements
To create validation rules, users must have the following permissions:
- Administrator System Role
Understanding Validation Rules
Validation Rules ensure data quality by enforcing specific business logic when records are saved. They work by evaluating a formula against the record data and displaying an error message if the validation fails.
How Validation Rules Work
- User attempts to save a record (create or edit)
- All validation rules for the entity are evaluated
- If a validation rule formula evaluates to true, an error is triggered
- The error message is displayed to the user
- The record cannot be saved until the validation passes (formula evaluates to false)
Important: Validation formulas return true when there is an ERROR. This is the opposite of typical logic where true means success.
When Validation Rules Execute
Validation rules are evaluated:
- When creating new records
- When editing existing records
- Before the record is saved to the database
- For both user interface and API operations
Validation rules are NOT evaluated:
- When viewing records
- When running reports
- During bulk data loads (unless specifically configured)
Common Use Cases
- Ensure required fields are populated based on conditions
- Enforce business logic (e.g., close date must be in the future)
- Validate field combinations (e.g., if field A is filled, field B must also be filled)
- Ensure numeric ranges (e.g., discount cannot exceed 25%)
- Verify date relationships (e.g., end date must be after start date)
- Enforce picklist dependencies (e.g., certain status values require other fields)
Creating or Configuring a Validation Rule for an Entity
To create or configure a validation rule for an entity:
In the Setup Home page:
- If you want to configure a validation rule for a Magentrix Entity, click Create > Entities.
- If you want to configure a validation rule for a Salesforce integrated Entity, click Extend > Salesforce.
Click the Entity for which you want to add or configure a validation rule.
Select the Validations tab.
To create a validation rule:
To configure an existing validation rule:
- Click the validation rule
- Click Edit
Configure the following fields:
Name: Enter a name for the validation rule (e.g., "Opportunity Amount Required", "End Date After Start Date").
Entity: This field is automatically populated with the selected entity.
Active: Check the box to activate the validation rule. Inactive rules are not evaluated.
Description: Enter a description of the validation rule's purpose and business logic (optional but highly recommended).
Condition Formula: Enter the validation rule formula. The formula should evaluate to true when there is an error. See Building Condition Formulas below.
Error Message: Enter the error message that will be displayed when validation fails. Make this message clear and actionable.
Field: Select the field where the error message should appear. This field will be highlighted when the validation fails.
Click Save.
The validation rule is now active (if the Active checkbox is checked) and will be evaluated whenever users save records.
Building Condition Formulas
The Condition Formula is the heart of the validation rule. It must evaluate to true when there is an error condition.
Formula Builder Tools
When building formulas, you have access to:
Insert Field Dropdown: Select fields from the entity to reference in your formula. Use the Field Picker to browse available fields.
Functions Dropdown: Access functions for comparisons, date/time operations, logical operations, and text manipulation. See Functions and Merge Field section below.
Formula Syntax: Formulas must start with {! and end with }. All operations use function syntax rather than operators.
Key Formula Concepts
Formula Structure: All formulas begin with {! and end with }
Return Value: The formula must return true (error) or false (no error)
Field References: Reference fields using their API name from the Insert Field dropdown
Comparison Functions: Use Equal, NotEqual, LessThan, GreaterThan, LessThanOrEqual, GreaterThanOrEqual
Logical Functions: Use AND, OR, NOT for combining conditions. AND and OR can take any number of parameters.
Null Checking: Use IsNull() to check for blank values
Common Formula Patterns
Required field based on condition:
{!AND(Equal(Status,"Closed Won"),IsNull(CloseDate))}
Error if Status is "Closed Won" and Close Date is blank.
Date comparison:
{!LessThan(EndDate,StartDate)}
Error if End Date is before Start Date.
Numeric range validation:
{!OR(LessThan(Discount,0),GreaterThan(Discount,25))}
Error if Discount is less than 0 or greater than 25.
Conditional requirement:
{!AND(Equal(Type,"Renewal"),IsNull(PreviousContractNumber))}
Error if Type is "Renewal" but Previous Contract Number is blank.
Field dependency:
{!AND(NOT(IsNull(CustomField1)),IsNull(CustomField2))}
Error if Custom Field 1 has a value but Custom Field 2 is blank.
Complex business rule:
{!AND(Equal(Stage,"Closed Lost"),IsNull(LostReason),GreaterThan(Amount,10000))}
Error if Stage is "Closed Lost", Lost Reason is blank, and Amount exceeds 10,000.
Use Cases for Validation Rules
Use Case 1: Opportunity Close Requirements
Business Rule: When an opportunity is marked as Closed Won, the Close Date and Amount must be specified.
Formula:
{!AND(Equal(Stage,"Closed Won"),OR(IsNull(CloseDate),IsNull(Amount)))}
Error Message: "Close Date and Amount are required when Stage is Closed Won."
Field: Stage
Use Case 2: Date Range Validation
Business Rule: The End Date must be after the Start Date.
Formula:
{!AND(NOT(IsNull(StartDate)),NOT(IsNull(EndDate)),LessThan(EndDate,StartDate))}
Error Message: "End Date must be after Start Date."
Field: End Date
Use Case 3: Future Date Requirement
Business Rule: The Close Date cannot be in the past.
Formula:
{!AND(NOT(IsNull(CloseDate)),LessThan(CloseDate,Today()))}
Error Message: "Close Date cannot be in the past."
Field: Close Date
Use Case 4: Closed Lost Reason Required
Business Rule: If an opportunity is Closed Lost, a Lost Reason must be specified.
Formula:
{!AND(Equal(Stage,"Closed Lost"),IsNull(LostReason))}
Error Message: "Please specify a Lost Reason when marking an opportunity as Closed Lost."
Field: Lost Reason
Use Case 5: Discount Authorization
Business Rule: Discounts over 15% require manager approval.
Formula:
{!AND(GreaterThan(Discount,15),NOT(ManagerApproved))}
Error Message: "Discounts over 15% require manager approval."
Field: Discount
Use Case 6: Email Format Validation
Business Rule: If a secondary email is provided, it must be different from the primary email.
Formula:
{!AND(NOT(IsNull(SecondaryEmail)),Equal(SecondaryEmail,PrimaryEmail))}
Error Message: "Secondary Email must be different from Primary Email."
Field: Secondary Email
Available Functions
Validation rule formulas support the same functions as formula fields. See Configuring Magentrix Entity Formula Fields for a complete list of available functions.
Most Commonly Used Functions in Validation Rules
IsNull(field) - Returns true if field is blank NOT(expression) - Reverses boolean value AND(expr1, expr2, ...) - Returns true if all expressions are true (accepts any number of parameters) OR(expr1, expr2, ...) - Returns true if any expression is true (accepts any number of parameters) Equal(field, value) - Returns true if field equals value NotEqual(field, value) - Returns true if field does not equal value LessThan(field1, field2) - Returns true if field1 is less than field2 GreaterThan(field1, field2) - Returns true if field1 is greater than field2 LessThanOrEqual(field1, field2) - Returns true if field1 is less than or equal to field2 GreaterThanOrEqual(field1, field2) - Returns true if field1 is greater than or equal to field2 Today() - Returns current date Text(value) - Converts value to text for comparison Len(text) - Returns character length
Specifying Error Field Location
The Field setting determines where the error message appears on the page:
Field Selection
- Select the field most relevant to the validation error
- The selected field will be highlighted in red when the validation fails
- The error message appears next to the selected field
- Users can easily identify which field needs correction
Best Practices for Field Selection
- Choose the field the user needs to correct
- For multi-field validations, select the primary field involved
- If validation involves a condition field and a required field, select the required field
- Be consistent in field selection across similar validation rules
Activating and Deactivating Validation Rules
Validation rules can be activated or deactivated to control when they are enforced:
Active Validation Rules
- Are evaluated every time a record is saved
- Display error messages when validation fails
- Prevent records from being saved when validation fails
- Apply to all users (cannot be bypassed based on role)
Inactive Validation Rules
- Are not evaluated
- Do not prevent records from being saved
- Can be reactivated at any time
- Useful for temporarily disabling validations during data loads or system changes
To Activate or Deactivate
- Navigate to the validation rule
- Click Edit
- Check or uncheck the Active checkbox
- Click Save
Best Practices and Recommendations
- Write clear error messages: Users should understand exactly what they need to fix. Avoid technical jargon.
- Test thoroughly: Test validation rules with various data scenarios including edge cases and blank values.
- Use ISNULL for blank checks: Always check if fields are blank before comparing them to avoid errors.
- Keep formulas readable: Use line breaks and indentation in complex formulas for easier maintenance.
- Document business logic: Add detailed descriptions explaining why the validation rule exists.
- Start inactive: Create validation rules as inactive, test them, then activate.
- Consider user experience: Too many validation rules can frustrate users. Apply them judiciously.
- Coordinate with required fields: Don't create validations that conflict with required field settings.
- Test with actual users: Have representative users test validation rules before full deployment.
- Handle null values carefully: Remember that null values behave differently than zero or empty strings.
- Use AND/OR appropriately: Understand that AND requires all conditions true, OR requires any condition true.
- Version control: Keep a log of validation rule changes for reference.
- Plan for exceptions: Consider if certain users or scenarios need to bypass validations.
Troubleshooting Tips
Issue: Validation rule not firing when expected.
Solution: Verify that the Active checkbox is checked. Also check that your formula logic is correct - remember that true means ERROR.
Issue: Validation rule firing when it shouldn't.
Solution: Review your formula logic. Test with actual data to see what the formula evaluates to. Use NOT() if you need to reverse the logic.
Issue: Error message appearing on wrong field.
Solution: Update the Field setting to point to the most relevant field for the validation error.
Issue: Formula syntax error.
Solution: Use the Insert Field and Functions dropdowns to ensure correct field API names and function syntax. Check for missing parentheses or quotes.
Issue: Validation preventing legitimate saves.
Solution: Review the business logic. The validation may be too restrictive. Consider if certain scenarios should be allowed.
Issue: Null value causing unexpected results.
Solution: Always use ISNULL() to check for blank values before performing comparisons or operations on fields.
Issue: Users bypassing validation through API.
Solution: Validation rules apply to API operations. If users are bypassing validations, check if the validation rule is Active and if the API operation is actually triggering validation.
Issue: Cannot save records due to validation, but error message unclear.
Solution: Rewrite the error message to be more specific and actionable. Tell users exactly what they need to do to fix the issue.
Issue: Validation rule conflicts with required field.
Solution: Review both the validation rule and required field settings. Ensure they work together logically. A field cannot be both required and conditionally validated unless the validation allows for the required state.
Issue: Complex formula too slow.
Solution: Simplify the formula if possible. Very complex formulas with many nested functions can impact save performance.
Interaction with Other Features
Required Fields
Required fields and validation rules work together:
- Required fields enforce that a field always has a value
- Validation rules can enforce conditional requirements based on other field values
- Both are evaluated before a record can be saved
Field Security
Field security affects what users can see and edit:
- Validation rules can reference fields users cannot see
- This can create confusing error messages
- Ensure validation rules reference fields visible to users
Workflows and Automation
Validation rules are evaluated before workflows:
- Records must pass all validations before workflows execute
- This ensures workflows operate on valid data
- Plan validation rules with automation in mind
Data Loads
During bulk data operations:
- Validation rules may need to be deactivated temporarily
- Reactivate after data load completes
- Consider data quality before disabling validations
See Also
Jump to Magentrix Entity Checklist
<< Enabling Field Search for Entities | Configuring Sharing Filters >>