
Generating Validation Rule
Create or update Salesforce Validation Rules with correct metadata, formulas, and user-facing error messages.
Overview
generating-validation-rule is an agent skill for the Build phase that creates and modifies Salesforce ValidationRule metadata with formulas and error messages.
Install
npx skills add https://github.com/forcedotcom/sf-skills --skill generating-validation-ruleWhat is this skill?
- Covers ValidationRule metadata: fullName, formulas, and save-time enforcement
- Generates rules that block saves when formula expressions evaluate to TRUE
- Includes purposeful error messages to guide record editors
- Supports create, modify, validate, and troubleshooting of deployment errors
- Always-on trigger for any validation rule or formula validation task
Adoption & trust: 721 installs on skills.sh; 513 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Invalid or incomplete Salesforce records can be saved because business rules are not enforced declaratively at save time.
Who is it for?
Solo builders and admins shipping Salesforce customizations who need save-time data quality without new Apex.
Skip if: Complex async validation, heavy UI-only checks, or non-Salesforce stacks where ValidationRule metadata does not apply.
When should I use this skill?
Users mention validation rules, field validation, data quality rules, formula validation, error messages, validation logic, validation errors, or any validation rule work on Salesforce.
What do I get? / Deliverables
You get ValidationRule metadata with correct formulas and user-facing errors that prevent bad saves and clarify deployment issues.
- ValidationRule metadata with fullName and formula
- User-facing error message text
- Guidance for validate and troubleshoot deployment issues
Recommended Skills
Journey fit
Validation rules enforce business logic at the Salesforce data layer during product build on the platform. Work targets server-side record validation metadata rather than Lightning UI, marketing, or deploy-only checklists.
How it compares
Use for declarative save-time rules instead of ad-hoc formula snippets that omit metadata structure and deployment constraints.
Common Questions / FAQ
Who is generating-validation-rule for?
Salesforce developers and admins using agent-assisted metadata work who need validation rules, field validation, and data-quality enforcement on standard or custom objects.
When should I use generating-validation-rule?
Use during Build backend work when creating or changing validation rules, fixing formula validation errors, updating error messages, or troubleshooting validation-rule deployment failures.
Is generating-validation-rule safe to install?
It guides metadata that can block production saves if formulas are wrong; review the Security Audits panel on this page and test rules in a sandbox before deploying.
SKILL.md
READMESKILL.md - Generating Validation Rule
## 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 1. Formula XML Handling(MOST COMMON ERROR) - ANY errorConditionFormula containing XML tags MUST be inside a CDATA section in the metadata XML. 2. 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). 3. File Format Requirement - Validation rule files MUST always use the `.validationRule-meta.xml` extension.