platform-validation-rule-generate — Claude Code skill: Salesforce
A skill for building and editing Salesforce validation rules: it assembles the metadata, the formula and the error message. Useful when bad records must not be saved.
npx skills add forcedotcom/sf-skills --skill platform-validation-rule-generate -a claude-codeWhat platform-validation-rule-generate does
The skill handles ValidationRule, the declarative Salesforce component that evaluates a formula on save and blocks the operation when the formula returns TRUE. The agent fills in fullName, the active flag, errorConditionFormula and errorMessage (up to 255 characters), and keeps to the naming rules: the name starts with a letter, does not end with an underscore, has no consecutive underscores and stays within 40 characters.
Inside sits the metadata spec plus a list of common formula mistakes. TEXT() must not be used on text fields, VALUE() only on text fields, and DAY() and MONTH() need Date fields rather than Datetime. Checking a picklist field calls for ISPICKVAL(). The skill also spells out how to read instructions: "update the formula to ..." replaces the logic outright, while "update the formula to also ..." appends a condition through AND() or OR().
XML is where deployments break most often. Any formula containing XML tags has to sit inside a CDATA section, or the deploy fails. The rule file must carry the .validationRule-meta.xml extension. The skill targets API version 60.0 and above, so on older orgs the metadata simply will not build.
What it helps with
- create a validation rule to enforce data quality
- stop incomplete records from being saved
- generate rule metadata together with the formula
- fix a formula that breaks the deploy because of XML
- read a validation error and rewrite the condition
Example prompts for the agent
- Create a validation rule on Account that blocks saving when BillingCountry is empty, with a clear error message.
- Update the rule formula to also check whether StageName changed, using ISCHANGE().
- Why does this validation rule fail to deploy? Check the formula and the XML.
How to install platform-validation-rule-generate
1Skills CLI (Vercel)
npx skills add forcedotcom/sf-skills --skill platform-validation-rule-generate -a claude-code2Manually: put the files in place
~/.claude/skills/platform-validation-rule-generate/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/platform-validation-rule-generate/
1Skills CLI (Vercel)
npx skills add forcedotcom/sf-skills --skill platform-validation-rule-generate -a codex2Manually: put the files in place
.agents/skills/platform-validation-rule-generate/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add forcedotcom/sf-skills --skill platform-validation-rule-generate -a cursor2Manually: put the files in place
.cursor/skills/platform-validation-rule-generate/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install forcedotcom/sf-skills platform-validation-rule-generate2Manually: put the files in place
.github/skills/platform-validation-rule-generate/SKILL.md1Skills CLI (Vercel)
npx skills add forcedotcom/sf-skills --skill platform-validation-rule-generate -a gemini-cli2Platform CLI
gemini skills install https://github.com/forcedotcom/sf-skills --path skills/platform-validation-rule-generateManually: put the files in place
.devin/skills/platform-validation-rule-generate/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add forcedotcom/sf-skills --skill platform-validation-rule-generate -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about platform-validation-rule-generate
How do I install platform-validation-rule-generate in Claude?
Run npx skills add forcedotcom/sf-skills --skill platform-validation-rule-generate -a claude-code. The skill lands in ~/.claude/skills/platform-validation-rule-generate/SKILL.md.
What does platform-validation-rule-generate do?
It helps create, modify and validate Salesforce validation rules: it writes the metadata, the condition formula and the error text, and flags formulas that will not work.
Which API version does this skill need?
At least 60.0. On orgs running an older version the rule metadata will not build.
Source text
SKILL.md · Apache-2.0
---
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
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.
© forcedotcom · Apache-2.0 · forcedotcom/sf-skills