Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add forcedotcom/sf-skills --skill platform-validation-rule-generate -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/platform-validation-rule-generate/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/platform-validation-rule-generate/

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

Similar skills

Everything for Backend and APIs →

From the same set167

platform-custom-field-generate Generates and validates Salesforce CustomField metadata XML for SFDX projects. It prevents Metadata API deployment failures across relationship fields, picklists, and formulas. CX Codex +1 6,500installs platform-custom-object-generate Generates and validates Salesforce custom object XML, and keeps the object description current after field or validation rule edits. CX Codex +1 6,400installs dx-code-analyzer-run Runs Salesforce Code Analyzer over your project and works through the results: engines, categories, severities, auto-fixes. Useful ahead of an AppExchange review. CX Codex +1 6,400installs automation-flow-generate Turns a plain-language request into Salesforce Flow metadata and returns the XML. Useful when describing an automation beats dragging elements in a builder. CX Codex +1 6,300installs platform-data-manage Salesforce data operations skill for sf CLI and anonymous Apex. It creates test datasets, runs bulk imports, and cleans up records across scratch orgs and sandboxes. CX Codex +1 6,100installs experience-lwc-generate A skill for building Lightning Web Components: bundles, wire service patterns, SLDS 2 styling and Jest tests. Useful whenever you touch files under lwc/. CX Codex +1 6,200installs platform-sharing-rules-generate A skill for Salesforce record-level access: creates, edits and deletes Sharing Rules metadata through sf. Useful when sharing rules are managed from the editor, not the UI. CX Codex +1 6,000installs platform-flexipage-generate Builds and validates Salesforce Lightning FlexiPages using CLI scaffolding. It prevents XML structure errors when editing RecordPage, AppPage, and HomePage layouts. CX Codex +1 6,000installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor