agentsclimarketplace

Salesforce cli

Skill georgekhananaev/claude-skills-vault/.claude/skills/salesforce-cli

A curated collection of high impact skills for Claude Code designed to supercharge the senior full stack workflow. This vault automates the repetitive parts of development like architectural reviews, TDD cycles, and PR management so you can stay in flow. It is a force multiplier for shipping clean, production ready code at scale. πŸš€βš‘οΈ

Install
npx -y skills add georgekhananaev/claude-skills-vault --skill salesforce-cli

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

Safety-first Salesforce CLI skill wrapping `sf` (v2). This skill should be used when performing Salesforce operations β€” SOQL/SOSL queries, metadata deploy/retrieve, data import/export, Apex execution, org management, auth, and platform events. Enforces risk classification w/ mandatory confirmation for all write/destructive operations. Integrates w/ Salesforce MCP servers and file-converter skill for format conversion.

SKILL.md

18.7 KB, as published. Nobody here has run it

Salesforce CLI

Safety-first wrapper for Salesforce CLI (sf v2). Every command is classified by risk level before execution. NEVER modify Salesforce data or metadata without explicit user permission.

When to Use

  • User asks to query Salesforce data (SOQL/SOSL)
  • User asks to deploy or retrieve metadata
  • User asks to export/import data (CSV, JSON, tree)
  • User asks to execute Apex code
  • User asks to manage orgs (scratch, sandbox, production)
  • User asks to authenticate w/ Salesforce
  • User asks to work w/ platform events or CDC
  • User asks to manage packages or permissions
  • User asks to interact w/ Salesforce APIs (REST, Bulk, Tooling)

Prerequisites

  1. Install: npm install -g @salesforce/cli or brew install sf
  2. Auth: sf org login web (interactive) or sf org login jwt (CI/CD)
  3. Verify: sf --version (requires v2.x)
  4. Default org: sf config set target-org <alias>

Safety Model

Every sf command falls into one of four risk tiers. Default mode is read-only.

TierAction RequiredExamples
SafeExecute immediatelysf org list, sf data query, sf project retrieve preview
WriteAskUserQuestion BEFORE executingsf data create record, sf project deploy start --dry-run
DestructiveAskUserQuestion w/ explicit consequencessf project deploy start, sf data delete, sf org delete
ForbiddenMulti-step validation, NEVER auto-confirmBulk delete in production, mass data wipe, production org delete

See references/safety-rules.md for full classification and confirmation templates.

Production Guardrails

Detect org type before ANY write operation:

sf org display --target-org <alias> --json

Check instanceUrl and isScratch/isSandbox fields:

  • login.salesforce.com or no sandbox/scratch flag β†’ PRODUCTION β†’ extra confirmation required
  • test.salesforce.com or isSandbox: true β†’ Sandbox
  • isScratch: true β†’ Scratch org

For production orgs: ALL write operations require AskUserQuestion w/ org alias typed confirmation.

Fail-Safe Principles

  1. If org type detection fails β†’ BLOCK all operations (never assume non-production)
  2. If unsure about tier β†’ classify HIGHER (Write β†’ Destructive, Destructive β†’ Forbidden)
  3. Bulk operations always require row count preview before confirmation
  4. Deploys with destructiveChanges.xml are FORBIDDEN in production via scripts
  5. --test-level NoTestRun is BLOCKED for production deployments
  6. Apex code must be shown to user BEFORE execution (never run sight-unseen)
  7. Permission set changes require warning about privilege escalation / lockout risks
  8. Field/object deletions in deploys require warning about cascade impacts (reports, flows, integrations)
  9. Sandbox refresh requires explicit acknowledgment that ALL data will be overwritten
  10. PII fields in queries trigger a warning (Email, Phone, Birthdate, SSN, etc.)

Decision Flow

Command received
  β†’ Detect target org type (prod/sandbox/scratch)
  β†’ Classify risk tier (see Quick Reference)
  β†’ Safe?        Execute immediately
  β†’ Write?       AskUserQuestion β†’ wait for answer β†’ execute or cancel
  β†’ Destructive? AskUserQuestion w/ consequences β†’ wait β†’ execute or cancel
  β†’ Forbidden?   Warn β†’ require typed confirmation β†’ final confirm β†’ execute or cancel
  β†’ PRODUCTION?  Add extra confirmation step regardless of tier

Quick Reference

Safe (read-only, execute immediately)

CommandDescription
sf org listList authorized orgs
sf org list --allInclude expired scratch orgs
sf org displayDisplay org info
sf org openOpen org in browser
sf config listList config values
sf config get target-orgGet default org
sf alias listList aliases
sf data query --query "..."SOQL query (w/ mandatory LIMIT)
sf data search --query "..."SOSL search
sf data get recordGet single record
sf project retrieve previewPreview what would be retrieved
sf project deploy previewPreview what would be deployed
sf apex list logList debug logs
sf apex get logGet debug log content
sf apex tail logTail logs in real-time
sf api request rest (GET)Read-only REST API calls
sf limits api displayDisplay API limits
sf sobject describe --sobject <name>Describe object schema (fields, types)
sf package listList packages
sf package version listList package versions
sf plugins listList installed plugins
sf doctorRun diagnostics
sf org list authList auth connections (sf auth list = legacy alias)

Write (AskUserQuestion required)

CommandDescription
sf data create recordCreate a single record
sf data update recordUpdate a single record
sf data import treeImport data from tree files
sf project deploy start --dry-runValidate deployment (no changes)
sf project retrieve startRetrieve metadata to local
sf org create scratchCreate scratch org
sf alias setSet an alias
sf config setSet config value
sf package createCreate a package
sf package version createCreate package version

Destructive (AskUserQuestion w/ consequences)

CommandDescription
sf project deploy start (no dry-run)Deploy metadata (modifies org)
sf data delete recordDelete a single record
sf data delete bulkBulk delete records
sf data update bulkBulk update records β€” can corrupt data at scale
sf data import bulkBulk import β€” can create thousands of duplicate records
sf data upsert bulkBulk upsert β€” incorrect key can overwrite wrong records
sf apex runExecute anonymous Apex
sf org delete scratchDelete scratch org
sf org delete sandboxDelete sandbox
sf org create sandboxCreate sandbox (long-running, uses resources)
sf org assign permsetAssign permission set β€” can escalate privileges or lock users out
sf package installInstall package β€” can modify schema, automation, and data
sf package uninstallUninstall package
sf org logoutRemove org auth
sf api request rest -X POST/PUT/PATCH/DELETEWrite/delete REST API calls

Forbidden (multi-step validation)

CommandDescription
sf org delete targeting productionDelete production org connection
Bulk delete in productionMass data deletion in production
sf data delete bulk w/o WHERE in source queryFull-table data wipe risk
sf project deploy start w/ destructiveChanges.xml in prodDeploy destructive metadata changes to production
sf project deploy start --test-level NoTestRun in prodSkip tests in production (BLOCKED)
sf org refresh sandboxRefresh sandbox β€” overwrites ALL data and customizations
sf org logout --allRemove ALL org auth β€” can break CI/CD pipelines
Bulk loops w/o limitsAny loop running delete/update w/o LIMIT
sf apex run in production w/o reviewExecute unreviewed Apex in production
Dangerous deploy flags in prod--ignore-conflicts, --ignore-warnings, --purge-on-delete

SOQL/SOSL Query Safety

Mandatory rules for ALL queries:

  1. Always add LIMIT β€” Default to LIMIT 200 if user omits
  2. Never use SELECT * β€” Expand fields via sf sobject describe --sobject <name> or ask user
  3. Production queries β€” Require WHERE clause unless object is known to be small
  4. Tooling API queries β€” Use --use-tooling-api flag for metadata queries
# Safe SOQL query
sf data query --target-org my-org \
  --query "SELECT Id, Name, Industry FROM Account WHERE Industry = 'Technology' LIMIT 100"

# SOQL w/ relationships
sf data query --target-org my-org \
  --query "SELECT Id, Name, (SELECT Id, FirstName FROM Contacts) FROM Account LIMIT 50"

# SOQL w/ output format
sf data query --target-org my-org \
  --query "SELECT Id, Name FROM Account LIMIT 100" \
  --result-format csv --output-file accounts.csv

# Tooling API query
sf data query --target-org my-org --use-tooling-api \
  --query "SELECT Id, Name FROM ApexClass WHERE Name LIKE '%Test%' LIMIT 50"

# SOSL search
sf data search --target-org my-org \
  --query "FIND {Acme} IN NAME FIELDS RETURNING Account(Id, Name LIMIT 50)"

See references/soql-sosl.md for query patterns, date literals, and aggregate examples.

Data Export/Import

Export (Safe tier β€” read-only)

# CSV export
sf data query --target-org my-org \
  --query "SELECT Id, Name FROM Account LIMIT 200" \
  --result-format csv --output-file accounts.csv

# JSON export
sf data query --target-org my-org \
  --query "SELECT Id, Name FROM Account LIMIT 200" \
  --json > accounts.json

# Tree export (preserves relationships)
sf data export tree --target-org my-org \
  --query "SELECT Id, Name, (SELECT Id, FirstName FROM Contacts) FROM Account LIMIT 50" \
  --output-dir ./data

# Bulk export (large datasets)
sf data export bulk --target-org my-org \
  --query "SELECT Id, Name FROM Account" \
  --output-file accounts.csv

Import (Write/Destructive tier β€” confirmation required)

# Tree import (Write)
sf data import tree --target-org my-org --files Account.json,Contact.json

# Bulk import (Write)
sf data import bulk --sobject Account --file accounts.csv --target-org my-org

# Bulk upsert (Write)
sf data upsert bulk --sobject Account --file data.csv \
  --external-id External_Id__c --target-org my-org

File-Converter Integration

Convert between formats using the file-converter skill:

# Salesforce JSON β†’ CSV (for spreadsheets)
python3 .claude/skills/file-converter/scripts/csv_json_yaml.py accounts.json accounts.csv

# CSV β†’ JSON (for API import)
python3 .claude/skills/file-converter/scripts/csv_json_yaml.py data.csv data.json

# JSON β†’ YAML (for config/review)
python3 .claude/skills/file-converter/scripts/csv_json_yaml.py accounts.json accounts.yaml

# Export β†’ Convert β†’ Report pipeline
sf data query --target-org my-org \
  --query "SELECT Id, Name FROM Account LIMIT 200" --json > data.json
python3 .claude/skills/file-converter/scripts/csv_json_yaml.py data.json report.csv

See references/data-operations.md for bulk patterns and tree format details.

Metadata Deploy/Retrieve

Retrieve (Write tier β€” modifies local files)

# Retrieve by source
sf project retrieve start --source-dir force-app --target-org my-org

# Retrieve by metadata type
sf project retrieve start --metadata ApexClass --target-org my-org

# Retrieve by manifest
sf project retrieve start --manifest package.xml --target-org my-org

Deploy (Destructive tier β€” modifies org)

Always validate first:

# Step 1: Preview (Safe)
sf project deploy preview --source-dir force-app --target-org my-org

# Step 2: Validate / dry-run (Write β€” confirm first)
sf project deploy start --source-dir force-app --target-org my-org --dry-run

# Step 3: Actual deploy (Destructive β€” confirm w/ consequences)
sf project deploy start --source-dir force-app --target-org my-org

# Production deploy (always w/ tests)
sf project deploy start --source-dir force-app --target-org prod-org \
  --test-level RunLocalTests

Apex Execution

Always show code before running. Always confirm.

# Step 1: Display the Apex code to the user (MANDATORY)
cat script.apex

# Step 2: AskUserQuestion β€” "Execute this Apex in <org>?"

# Step 3: Execute (Destructive tier)
sf apex run --target-org my-org --file script.apex

# Run tests (Write tier)
sf apex run test --target-org my-org --class-names MyClassTest --code-coverage

# Get latest log
sf apex get log --target-org my-org --number 1

Org Management

Scratch Orgs

# Create (Write)
sf org create scratch --definition-file config/project-scratch-def.json \
  --alias my-scratch --duration-days 7

# List (Safe)
sf org list --all

# Delete (Destructive β€” confirm first)
sf org delete scratch --target-org my-scratch

Sandboxes

# Create (Destructive β€” long-running, consumes resources)
sf org create sandbox --target-org prod-org --name dev-sandbox --alias dev-sb

# Refresh (Destructive)
sf org refresh sandbox --target-org dev-sb

# Delete (Destructive β€” confirm first)
sf org delete sandbox --target-org dev-sb

Authentication

# Web login (interactive β€” recommended for development)
sf org login web --alias my-org --set-default

# Sandbox login
sf org login web --alias my-sandbox --instance-url https://test.salesforce.com

# JWT login (CI/CD β€” non-interactive)
sf org login jwt --client-id <consumer_key> --jwt-key-file server.key \
  --username [email protected] --alias my-org

# SFDX Auth URL (transfer auth between systems)
sf org login sfdx-url --sfdx-url-file auth.txt --alias my-org

# Device flow (headless environments)
sf org login device

# Verify auth
sf org display --target-org my-org
sf auth list

See references/auth-flows.md for detailed setup instructions.

MCP Server Integration

Official Salesforce MCP Server (recommended)

{
  "mcpServers": {
    "salesforce-dx": {
      "command": "npx",
      "args": ["-y", "@salesforce/mcp", "--orgs", "DEFAULT_TARGET_ORG"]
    }
  }
}

Available toolsets: Core, Orgs, Data, Users, Metadata, Testing, Code-Analysis, LWC, Aura, Mobile, Scale Products.

Tool Detection Flow

1. Check: Are Salesforce MCP tools available? (ToolSearch "salesforce")
   β†’ YES: Use MCP tools (structured, validated)
   β†’ NO:  Fall back to sf CLI commands
   β†’ NO CLI: Guide user through installation

Community MCP Servers

ServerToolsBest For
@salesforce/mcp (official)60+Full DX workflow, LWC, testing, metadata
tsmztech/mcp-server-salesforce16CRUD, schema, Apex, SOSL
advancedcommunities/salesforce-mcp-server36Apex, testing, code analysis, data export

See references/mcp-integration.md for setup and toolset details.

Direct API Access

# REST API (Safe for GET, Write/Destructive for others)
sf api request rest /services/data/v67.0/sobjects/Account/describe
sf api request rest /services/data/v67.0/query?q=SELECT+Id+FROM+Account+LIMIT+10

# GraphQL
sf api request graphql --body query.graphql --target-org my-org

# Composite (multiple operations in one call)
sf api request rest /services/data/v67.0/composite --body composite.json -X POST

Platform Events & CDC

# Publish platform event (Destructive β€” triggers automation)
sf data create record --sobject MyEvent__e --values "Field1__c='value'" --target-org my-org

# Subscribe to events (Safe β€” read-only)
sf apex run --target-org my-org --file subscribe_events.apex

# Check CDC-enabled objects (Safe)
sf data query --target-org my-org --use-tooling-api \
  --query "SELECT QualifiedApiName FROM EntityDefinition WHERE IsEnabledForChangeDataCapture = true LIMIT 100"

AskUserQuestion Integration

For ALL write, destructive, and forbidden operations, use AskUserQuestion w/ tailored options.

Data Modification Example

question: "Create a new Account record in <org-alias> (<org-type>)?"
header: "SF Write"
options:
  - label: "Create record"
    description: "Insert the Account record with the specified field values"
  - label: "Cancel"
    description: "Do not create any records"

Deploy Example

question: "Deploy metadata to <org-alias> (<org-type>)? <N> components will be modified."
header: "SF Deploy"
options:
  - label: "Validate only (dry-run)"
    description: "Run validation without making changes"
  - label: "Deploy now"
    description: "Deploy and modify the target org"
  - label: "Cancel"
    description: "Do not deploy"

Apex Execution Example

question: "Execute the following Apex in <org-alias> (<org-type>)?\n\n<code preview>"
header: "SF Apex"
options:
  - label: "Execute"
    description: "Run the Apex code in the target org"
  - label: "Cancel"
    description: "Do not execute"

See references/safety-rules.md for all confirmation templates.

Error Handling

ErrorCauseFix
sf: command not foundNot installednpm install -g @salesforce/cli
No default org setNo target orgsf config set target-org <alias>
INVALID_SESSION_IDAuth expiredsf org login web --alias <org>
MALFORMED_QUERYBad SOQL syntaxCheck query, verify field names
INVALID_FIELDWrong field nameUse sf sobject describe --sobject <name> to check fields
REQUEST_LIMIT_EXCEEDEDAPI limit hitCheck sf limits api display, wait or optimize
DUPLICATE_VALUEUnique constraintCheck external IDs, use upsert instead
REQUIRED_FIELD_MISSINGMissing fieldCheck object requirements w/ describe
DEPLOY_FAILEDDeploy validation errorCheck error details, fix code, redeploy

Shell Safety

  • No interactive mode: Always provide explicit flags, never rely on interactive prompts
  • No pagers: Pipe to cat if output may trigger a pager: sf org list | cat
  • Always specify org: Use --target-org to prevent accidental operations on wrong org
  • Quote arguments: Always quote query strings and multi-word values
  • JSON output: Use --json for programmatic parsing
  • Never print tokens: Auth tokens, keys, and secrets must never appear in output

Self-Healing

sf v2 renames commands across releases. On any error: sf <topic> --help (authoritative for the installed version) β†’ if unclear, WebFetch https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_unified.htm β†’ adjust β†’ re-run. Never guess flags twice; surface renamed commands w/ the doc link.

Integration

Pairs with:

  • file-converter β€” Convert Salesforce exports between CSV, JSON, YAML, XML formats
  • github-cli β€” Commit and PR Salesforce metadata changes
  • code-quality β€” Review Apex code before deployment
  • token-optimizer β€” Compress large query results or metadata descriptions

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.