
Generating Validation Rule
Generate and troubleshoot Salesforce Validation Rule metadata with formulas and user-facing error messages so bad records cannot be saved.
Overview
Generating Validation Rule is an agent skill for the Build phase that creates, modifies, and validates Salesforce Validation Rule metadata with formulas and error messages.
Install
npx skills add https://github.com/forcedotcom/afv-library --skill generating-validation-ruleWhat is this skill?
- Covers full ValidationRule metadata specification including fullName API naming rules
- Produces formula expressions that block saves when logic evaluates to TRUE
- Supports create, modify, validate, and deployment-error troubleshooting for validation rules
- Enforces business and data-quality rules with meaningful field-level error messages
- Always invoked for any validation rule work per skill triggers
Adoption & trust: 1.4k installs on skills.sh; 512 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need Salesforce records to obey business rules at save time but lack correct ValidationRule metadata, formulas, or deployable error messaging.
Who is it for?
Indie teams and solo builders extending Salesforce objects who want declarative validation instead of custom save hooks for every rule.
Skip if: Teams not on Salesforce, or flows that only need client-side form validation without platform metadata deploys.
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 deployable ValidationRule definitions with valid API names, TRUE-blocking formulas, and user-facing errors that stop invalid saves before they reach downstream automations.
- ValidationRule metadata with fullName, formula, and error message fields
- Guidance for troubleshooting related deployment errors
Recommended Skills
Journey fit
Validation rules are declarative Salesforce metadata authored and deployed during product build, alongside objects and business logic on the platform. Confluence-style platform wiring is not the focus—this skill targets Salesforce’s data-layer integration surface (ValidationRule metadata) rather than generic REST glue.
How it compares
Use for Salesforce ValidationRule metadata generation—not generic JSON-schema or Zod validation outside the Salesforce data layer.
Common Questions / FAQ
Who is generating-validation-rule for?
Solo builders and small teams shipping Salesforce apps or org customizations who enforce data quality with declarative validation rules rather than only UI hints.
When should I use generating-validation-rule?
Use during Build when creating or changing Validation Rules, fixing formula validation errors, tuning error messages, or resolving deployment issues tied to validation metadata—especially before Ship when data integrity gates production rollouts.
Is generating-validation-rule safe to install?
Review the Security Audits panel on this Prism page and your org’s change-management process before deploying generated rules to production; validation changes can block legitimate saves if formulas are wrong.
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.