platform-validation-rule-generate
forcedotcom/sf-skills
Generate and validate Salesforce validation rules with formula enforcement and error messaging.
What is platform-validation-rule-generate?
This skill creates, modifies, and validates Salesforce Validation Rules that enforce data quality and business logic at the data layer. Use it when you need to prevent invalid records from being saved, create field validation formulas, or troubleshoot validation rule deployment errors.
- Create validation rules with formula-based error conditions
- Enforce business rules and data quality constraints at the record level
- Generate validation rule metadata with proper XML formatting and CDATA sections
- Apply Salesforce formula functions correctly (ISPICKVAL, ISCHANGE, DATE functions, etc.)
- Display custom error messages up to 255 characters when validation fails
- Troubleshoot and fix validation rule deployment errors
How to install platform-validation-rule-generate
npx skills add https://github.com/forcedotcom/sf-skills --skill platform-validation-rule-generate- Salesforce org with API version 60.0 or higher
- Access to create or modify validation rules on target objects
- Understanding of Salesforce formula syntax and field types
How to use platform-validation-rule-generate
- 1.Install the skill using: npx skills add https://github.com/forcedotcom/sf-skills --skill platform-validation-rule-generate
- 2.Describe the validation rule you need (e.g., field constraints, cross-field logic, error message)
- 3.Provide the object name and field names involved in the validation
- 4.Specify the error message to display when the rule triggers
- 5.The skill will generate the validation rule metadata with proper XML formatting and formula syntax
Use cases
- Prevent users from saving records with incomplete or invalid field combinations
- Enforce date range constraints (e.g., end date must be after start date)
- Validate picklist field values against specific business rules using ISPICKVAL()
- Check if a field has changed using ISCHANGE() to trigger conditional validation
- Create cross-field validation logic to ensure data consistency across related fields
- Salesforce administrators managing data quality
- Developers building declarative validation logic
- Business analysts defining record-level business rules
- Teams enforcing compliance and data governance policies
platform-validation-rule-generate FAQ
Use ISPICKVAL() when checking equality of picklist type fields. For other field types, use standard equality operators.
The formula must return FALSE when validation passes (no error). It returns TRUE to trigger the validation error.
Any errorConditionFormula containing XML tags must be wrapped in a CDATA section in the metadata XML to prevent XML parsing errors.
Use the ISCHANGE() function to detect if a field's value has been modified during the save operation.
'Update to' means replace the entire formula; 'update to also' 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: platform-validation-rule-generate 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" domains: ["Platform"] minApiVersion: "60.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.

platform-value-set-generate
Create and customize Salesforce reusable picklists (GlobalValueSet and StandardValueSet metadata).

platform-widget-generate
Author complete HXL WidgetBundles with UEM tree, schema, and metadata for Salesforce Agentforce.

preparing-datacloud
Manage Data Cloud data streams, DLOs, transforms, and Document AI ingestion pipelines.

querying-soql
SOQL query generation, optimization, and analysis with 100-point scoring for Salesforce.

retrieving-datacloud
Query, search, and inspect Salesforce Data Cloud objects with SQL, vector search, and metadata introspection.

reviewing-lwc-mobile-offline
Review Lightning Web Components for Salesforce Mobile App offline compatibility using Komaci static analysis.