generating-validation-rule
forcedotcom/sf-skills
Create and manage Salesforce Validation Rules to enforce data quality and business logic at the data layer.
What is generating-validation-rule?
This skill helps you create, modify, and validate Salesforce Validation Rules that prevent invalid records from being saved. Use it when you need to enforce business rules, add field validation, or troubleshoot validation errors in your Salesforce org.
- Generate validation rule metadata with formulas that evaluate record data
- Prevent invalid or incomplete records from being saved to Salesforce
- Display meaningful error messages to guide users when validation fails
- Enforce business logic and data quality rules at the data layer
- Troubleshoot and fix validation rule deployment errors
How to install generating-validation-rule
npx skills add https://github.com/forcedotcom/sf-skills --skill generating-validation-rule- Access to a Salesforce org with metadata deployment capabilities
- Understanding of Salesforce formula syntax and field types
How to use generating-validation-rule
- 1.Define the validation rule name (fullName) following API naming conventions
- 2.Write the errorConditionFormula that returns TRUE when validation should fail
- 3.Compose a clear errorMessage (max 255 characters) explaining the validation error
- 4.Set active to true to enable the rule or false to disable it
- 5.Ensure any XML special characters in the formula are wrapped in CDATA sections
- 6.Deploy the validation rule metadata file with .validationRule-meta.xml extension
Use cases
- Prevent sales records from being saved without required fields or valid data combinations
- Enforce date logic such as preventing end dates before start dates
- Validate picklist field values and enforce conditional requirements based on other field values
- Prevent duplicate or conflicting data from being entered across related records
- Add custom error messages to guide users on proper data entry
- Salesforce administrators managing data quality
- Developers building validation logic into Salesforce objects
- Business analysts defining data governance rules
- Teams implementing data validation requirements
generating-validation-rule FAQ
The validation rule triggers and prevents the record from being saved, displaying the errorMessage to the user.
Use ISPICKVAL() when checking equality of picklist type fields. This is the required function for picklist comparisons in Salesforce formulas.
ISCHANGE() checks whether a field value has changed during the current save operation, useful for validating updates to specific fields.
Any errorConditionFormula containing XML tags must be wrapped in CDATA sections to prevent XML parsing errors during metadata deployment.
'Update to [action]' means replace the entire formula; 'update to also [action]' means keep existing logic and add new requirements, typically using AND() or OR() functions.
Full instructions (SKILL.md)
Source of truth, from forcedotcom/sf-skills.
name: generating-validation-rule description: "Use this skill when users need to create, modify, or validate Salesforce Validation Rules. Trigger when users mention validation rules, field validation, data quality rules, formula validation, error messages, or validation logic. Also use when users encounter validation errors, need to update formulas, or want to enforce business rules at the data layer. Always use this skill for any validation rule work." metadata: version: "1.0"
When to Use This Skill
Use this skill when you need to:
- Create validation rules to enforce data quality
- Prevent invalid records from being saved
- Generate validation rule metadata with formulas
- Add business logic validation to objects
- Troubleshoot deployment errors related to validation rules
Specification
ValidationRule Metadata Specification
📋 Overview
Validation Rules are declarative metadata components used to enforce data quality and business logic in Salesforce. They evaluate a formula expression when a record is saved and prevent the save operation if the expression returns TRUE.
🎯 Purpose
-Enforce business rules at the data layer -Prevent invalid or incomplete records from being saved -Display meaningful error messages to guide users
⚙️ Required Properties
Core Validation Rule Properties
-
fullName
- The unique API name of the validation rule
- Must start with a letter
- Can contain letters, numbers, and underscores
- Cannot end with an underscore
- Cannot contain consecutive underscores
- Cannot exceed 40 character.
-
active -Indicates whether the validation rule is enabled true → Rule is enforced false → Rule is inactive
-
errorConditionFormula
-
The logical formula that evaluates record data
-
Must return TRUE or FALSE
-
If TRUE, the validation rule triggers an error
-
errorMessage
- The message displayed to the user when validation fails
-
Maximum length: 255 characters
Specific Function Guidelines
- TEXT - TEXT() function MUST NOT be used with Text fields, to fix this you can just remove the TEXT() function.
- CASE - In salesforce CASE() function, last parameter is the default value. Admins often miss to provide this and number of parameters to CASE() function are always even.
- VALUE - VALUE() function should only be used with Text fields. If a number is being used as a parameter to the VALUE() function, remove the VALUE() function.
- DAY - DAY() function should only be used with Date fields. If a Datetime field is being used as a parameter to the DAY() function, convert it into a Date first.
- MONTH - MONTH() function should only be used with Date fields. If a Datetime field is being used as a parameter to the MONTH() function, convert it into a Date first.
- DATEVALUE - DATEVALUE() function should only be used with DateTime fields. If a Date is being used as a parameter to the DATEVALUE() function, remove the DATEVALUE() function.
- ISPICKVAL - If checking equality of a picklist type field, the function ISPICKVAL() MUST be used.
- ISCHANGE - Use ISCHANGE() function to check the value of a record has changed.
Critical Rules
-
Formula XML Handling(MOST COMMON ERROR)
- ANY errorConditionFormula containing XML tags MUST be inside a CDATA section in the metadata XML.
-
Interpretation of "Update" Instructions. When receiving instructions to modify a formula, distinguish between a replacement and an addition:
- "Update the formula to [Action]": Completely replace the existing formula logic with the new requirement.
- "Update the formula to also [Action]": Keep the existing logic and append the new requirement (usually by wrapping the logic in an AND() or OR() function).
-
File Format Requirement
- Validation rule files MUST always use the
.validationRule-meta.xmlextension.
- Validation rule files MUST always use the
Related skills
More from forcedotcom/sf-skills and the wider catalog.

generating-visual-diagrams
AI-powered rendered image generation for Salesforce visuals: ERDs, mockups, wireframes, and architecture diagrams.

getting-datacloud-schema
Retrieve Data Lake Object and Data Model Object schema from Salesforce Data Cloud via REST APIs.

handling-sf-data
Create, update, delete, and bulk import/export Salesforce records using sf CLI and anonymous Apex.

harmonizing-datacloud
Harmonize and unify Salesforce Data Cloud schemas, mappings, identity resolution, and profiles.

implementing-ui-bundle-agentforce-conversation-client
Embed and configure Agentforce Conversation Client in UI Bundle projects.

implementing-ui-bundle-file-upload
Programmatic file upload API with progress tracking for Salesforce UI bundles.