Salesforce Skill
Query and manage Salesforce CRM data via the Salesforce CLI (`sf`).
How to use it
Claude Code
- Run the line below. It pulls the whole folder into
~/.claude/skills/salesforce, including the files SKILL.md points to. - Describe your job in plain words. Claude Code follows the skill from there.
npx degit jdrhyne/agent-skills/skills/salesforce#main ~/.claude/skills/salesforceFor one project only, change the path to .claude/skills/salesforce. This skill also uses authUrl.txt, accounts.json, Account.json, Contact.json, Account-Contact-plan.json, limits.json — copying SKILL.md alone won't be enough. See the folder on GitHub.
Claude (web or desktop app)
- On this page open ⋯ → Download .md.
- Save it as SKILL.md in a folder, zip the folder, then Customize → Skills → + → Create skill → Upload a skill.
- Pick the file and Save. Claude shows the name and description and runs a security scan.
- Check the skill is switched on.
- Start a new chat and describe your job in plain words. The AI follows the skill from there.
ChatGPT or another app
- ChatGPT: make a Project and paste it into Instructions.
- Neither? Paste it at the top of a new chat — it works for that chat.
Not working?
- Check which app you pasted it into — the steps above name the right one.
- Some skills need the paid tier of Claude or ChatGPT.
Paste into Claude, ChatGPT or Cursor.
Source of Salesforce Skill
Show the full text385 lines
| name | description | homepage | metadata | permissions |
|---|---|---|---|---|
| salesforce | Query and manage Salesforce CRM data via the Salesforce CLI (`sf`). Run SOQL/SOSL queries, inspect object schemas, create/update/delete records, bulk import/export, execute Apex, deploy metadata, and make raw REST API calls. | https://developer.salesforce.com/tools/salesforcecli | {"clawdbot":{"emoji":"☁️","requires":{"bins":["sf"]},"install":[{"id":"npm","kind":"node","package":"@salesforce/cli","bins":["sf"],"label":"Install Salesforce CLI (npm)"}]}} | - exec: "Runs the Salesforce CLI for authenticated CRM queries, metadata inspection, and administrative tasks. - file_write: "Writes query exports or import files only when the user asks for saved artifacts. - network: "Uses the authenticated Salesforce org connection through the Salesforce CLI. |
Salesforce Skill
Use the Salesforce CLI (sf) to interact with Salesforce orgs. The CLI must be authenticated before use. Always add --json for structured output.
If the sf binary is not available, stop and ask the user to install the Salesforce CLI using the repo's declared install metadata or the official Salesforce CLI guide. After the CLI is available, authenticate with sf org login web before touching org data.
Safety Boundaries
- Do not create, update, delete, deploy, or execute Apex without explicit user confirmation.
- Do not reveal access tokens, auth URLs, refresh tokens, or verbose org-display output in chat.
- Do not export data to files unless the user asked for a saved artifact or bulk workflow.
- Do not target a production org by default when sandbox or staging access is available.
Authentication and Org Management
Log in (opens browser)
sf org login web --alias my-org
Other login methods:
# JWT-based login (CI/automation)
sf org login jwt --client-id <consumer-key> --jwt-key-file server.key --username [email protected] --alias my-org
# Login with an existing access token
sf org login access-token --instance-url https://mycompany.my.salesforce.com
# Login via SFDX auth URL (from a file)
sf org login sfdx-url --sfdx-url-file authUrl.txt --alias my-org
Manage orgs
# List all authenticated orgs
sf org list --json
# Display info about the default org (access token, instance URL, username)
sf org display --json
# Display info about a specific org
sf org display --target-org my-org --json
# Display with SFDX auth URL (sensitive - contains refresh token)
sf org display --target-org my-org --verbose --json
# Open org in browser
sf org open
sf org open --target-org my-org
# Log out
sf org logout --target-org my-org
Configuration and aliases
# Set default target org
sf config set target-org my-org
# List all config variables
sf config list
# Get a specific config value
sf config get target-org
# Set an alias
sf alias set [email protected]
# List aliases
sf alias list
Querying Data (SOQL)
Standard SOQL queries via the default API:
# Basic query
sf data query --query "SELECT Id, Name, Email FROM Contact LIMIT 10" --json
# WHERE clause
sf data query --query "SELECT Id, Name, Amount, StageName FROM Opportunity WHERE StageName = 'Closed Won'" --json
# Relationship queries (parent-to-child)
sf data query --query "SELECT Id, Name, (SELECT LastName, Email FROM Contacts) FROM Account LIMIT 5" --json
# Relationship queries (child-to-parent)
sf data query --query "SELECT Id, Name, Account.Name FROM Contact" --json
# LIKE for text search
sf data query --query "SELECT Id, Name FROM Account WHERE Name LIKE '%Acme%'" --json
# Date filtering
sf data query --query "SELECT Id, Name, CreatedDate FROM Lead WHERE CreatedDate = TODAY" --json
# ORDER BY + LIMIT
sf data query --query "SELECT Id, Name, Amount FROM Opportunity ORDER BY Amount DESC LIMIT 20" --json
# Include deleted/archived records
sf data query --query "SELECT Id, Name FROM Account" --all-rows --json
# Query from a file
sf data query --file query.soql --json
# Tooling API queries (metadata objects like ApexClass, ApexTrigger)
sf data query --query "SELECT Id, Name, Status FROM ApexClass" --use-tooling-api --json
# Output to CSV file
sf data query --query "SELECT Id, Name, Email FROM Contact" --result-format csv --output-file contacts.csv
# Target a specific org
sf data query --query "SELECT Id, Name FROM Account" --target-org my-org --json
For queries returning more than 10,000 records, use Bulk API instead:
sf data export bulk --query "SELECT Id, Name, Email FROM Contact" --output-file contacts.csv --result-format csv --wait 10
sf data export bulk --query "SELECT Id, Name FROM Account" --output-file accounts.json --result-format json --wait 10
Text Search (SOSL)
SOSL searches across multiple objects at once:
# Search for text across objects
sf data search --query "FIND {John Smith} IN ALL FIELDS RETURNING Contact(Name, Email), Lead(Name, Email)" --json
# Search in name fields only
sf data search --query "FIND {Acme} IN NAME FIELDS RETURNING Account(Name, Industry), Contact(Name)" --json
# Search from a file
sf data search --file search.sosl --json
# Output to CSV
sf data search --query "FIND {test} RETURNING Contact(Name)" --result-format csv
Single Record Operations
Get a record
# By record ID
sf data get record --sobject Contact --record-id 003XXXXXXXXXXXX --json
# By field match (WHERE-like)
sf data get record --sobject Account --where "Name=Acme" --json
# By multiple fields (values with spaces need single quotes)
sf data get record --sobject Account --where "Name='Universal Containers' Phone='(123) 456-7890'" --json
Create a record (confirm with user first)
sf data create record --sobject Contact --values "FirstName='Jane' LastName='Doe' Email='[email protected]'" --json
sf data create record --sobject Account --values "Name='New Company' Website=www.example.com Industry='Technology'" --json
# Tooling API object
sf data create record --sobject TraceFlag --use-tooling-api --values "DebugLevelId=7dl... LogType=CLASS_TRACING" --json
Update a record (confirm with user first)
# By ID
sf data update record --sobject Contact --record-id 003XXXXXXXXXXXX --values "Email='[email protected]'" --json
# By field match
sf data update record --sobject Account --where "Name='Old Acme'" --values "Name='New Acme'" --json
# Multiple fields
sf data update record --sobject Account --record-id 001XXXXXXXXXXXX --values "Name='Acme III' Website=www.example.com" --json
Delete a record (require explicit user confirmation)
# By ID
sf data delete record --sobject Account --record-id 001XXXXXXXXXXXX --json
# By field match
sf data delete record --sobject Account --where "Name=Acme" --json
Bulk Data Operations (Bulk API 2.0)
For large datasets (thousands to millions of records):
Bulk export
# Export to CSV
sf data export bulk --query "SELECT Id, Name, Email FROM Contact" --output-file contacts.csv --result-format csv --wait 10
# Export to JSON
sf data export bulk --query "SELECT Id, Name FROM Account" --output-file accounts.json --result-format json --wait 10
# Include soft-deleted records
sf data export bulk --query "SELECT Id, Name FROM Account" --output-file accounts.csv --result-format csv --all-rows --wait 10
# Resume a timed-out export
sf data export resume --job-id 750XXXXXXXXXXXX --json
Bulk import
# Import from CSV
sf data import bulk --file accounts.csv --sobject Account --wait 10
# Resume a timed-out import
sf data import resume --job-id 750XXXXXXXXXXXX --json
Bulk upsert
sf data upsert bulk --file contacts.csv --sobject Contact --external-id Email --wait 10
Bulk delete
# Delete records listed in CSV (CSV must have an Id column)
sf data delete bulk --file records-to-delete.csv --sobject Contact --wait 10
Tree export/import (for related records)
# Export with relationships into JSON tree format
sf data export tree --query "SELECT Id, Name, (SELECT Name, Email FROM Contacts) FROM Account" --json
# Export with a plan file (for multiple objects)
sf data export tree --query "SELECT Id, Name FROM Account" --plan --output-dir export-data
# Import from tree JSON files
sf data import tree --files Account.json,Contact.json
# Import using a plan definition file
sf data import tree --plan Account-Contact-plan.json
Schema Inspection
# Describe an object (fields, relationships, picklist values)
sf sobject describe --sobject Account --json
# Describe a custom object
sf sobject describe --sobject MyCustomObject__c --json
# Describe a Tooling API object
sf sobject describe --sobject ApexClass --use-tooling-api --json
# List all objects
sf sobject list --json
# List only custom objects
sf sobject list --sobject custom --json
# List only standard objects
sf sobject list --sobject standard --json
Execute Apex Code
# Execute Apex from a file
sf apex run --file script.apex --json
# Run interactively (type code, press Ctrl+D to execute)
sf apex run
# Run Apex tests
sf apex run test --test-names MyTestClass --json
# Get test results
sf apex get test --test-run-id 707XXXXXXXXXXXX --json
# View Apex logs
sf apex list log --json
sf apex get log --log-id 07LXXXXXXXXXXXX
REST API (Advanced)
Make arbitrary authenticated REST API calls:
# GET request
sf api request rest 'services/data/v62.0/limits' --json
# List API versions
sf api request rest '/services/data/' --json
# Create a record via REST
sf api request rest '/services/data/v62.0/sobjects/Account' --method POST --body '{"Name":"REST Account","Industry":"Technology"}' --json
# Update a record via REST (PATCH)
sf api request rest '/services/data/v62.0/sobjects/Account/001XXXXXXXXXXXX' --method PATCH --body '{"BillingCity":"San Francisco"}' --json
# GraphQL query
sf api request graphql --body '{"query":"{ uiapi { query { Account { edges { node { Name { value } } } } } } }"}' --json
# Custom headers
sf api request rest '/services/data/v62.0/limits' --header 'Accept: application/xml'
# Save response to file
sf api request rest '/services/data/v62.0/limits' --stream-to-file limits.json
Metadata Deployment and Retrieval
# Deploy metadata to an org
sf project deploy start --source-dir force-app --json
# Deploy specific metadata components
sf project deploy start --metadata ApexClass:MyClass --json
# Retrieve metadata from an org
sf project retrieve start --metadata ApexClass --json
# Check deploy status
sf project deploy report --job-id 0AfXXXXXXXXXXXX --json
# Generate a new Salesforce DX project
sf project generate --name my-project
# List metadata components in the org
sf project list ignored --json
Diagnostics
# Run CLI diagnostics
sf doctor
# Check CLI version
sf version
# See what is new
sf whatsnew
Common SOQL Patterns
-- Count records
SELECT COUNT() FROM Contact WHERE AccountId = '001XXXXXXXXXXXX'
-- Aggregate query
SELECT StageName, COUNT(Id), SUM(Amount) FROM Opportunity GROUP BY StageName
-- Date literals
SELECT Id, Name FROM Lead WHERE CreatedDate = LAST_N_DAYS:30
-- Subquery (semi-join)
SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Email LIKE '%@acme.com')
-- Polymorphic lookup
SELECT Id, Who.Name, Who.Type FROM Task WHERE Who.Type = 'Contact'
-- Multiple WHERE conditions
SELECT Id, Name, Amount FROM Opportunity WHERE Amount > 10000 AND StageName != 'Closed Lost' AND CloseDate = THIS_QUARTER
Guardrails
- Always use
--jsonfor structured, parseable output. - Never create, update, or delete records without explicit user confirmation. Describe the operation and ask before executing.
- Never delete records unless the user explicitly requests it and confirms the specific record(s).
- Never bulk delete or bulk import without user reviewing the file/query and confirming.
- Use
LIMITon queries to avoid excessive data. Start withLIMIT 10and increase if the user needs more. - For queries over 10,000 records, use
sf data export bulkinstead ofsf data query. - When the user asks to "find" or "search" a single object, use SOQL
WHERE ... LIKE '%term%'. When searching across multiple objects, use SOSL viasf data search. - Use
--target-org <alias>when the user has multiple orgs; ask which org if ambiguous. - If authentication fails or a session expires, guide the user through
sf org login web. - Bulk API 2.0 has SOQL limitations (no aggregate functions like
COUNT()). Use standardsf data queryfor those. - When describing objects (
sf sobject describe), the JSON output can be very large. Summarize the key fields, required fields, and relationships for the user rather than dumping the raw output.
| 1 | |
| 2 | name salesforce |
| 3 | description "Query and manage Salesforce CRM data via the Salesforce CLI (`sf`). Run SOQL/SOSL queries, inspect object schemas, create/update/delete records, bulk import/export, execute Apex, deploy metadata, and make raw REST API calls." |
| 4 | homepage https://developer.salesforce.com/tools/salesforcecli |
| 5 | metadata {"clawdbot":{"emoji":"☁️","requires":{"bins":["sf"]},"install":[{"id":"npm","kind":"node","package":"@salesforce/cli","bins":["sf"],"label":"Install Salesforce CLI (npm)"}]}} |
| 6 | permissions |
| 7 | - exec: "Runs the Salesforce CLI for authenticated CRM queries, metadata inspection, and administrative tasks." |
| 8 | - file_write: "Writes query exports or import files only when the user asks for saved artifacts." |
| 9 | - network: "Uses the authenticated Salesforce org connection through the Salesforce CLI." |
| 10 | |
| 11 | |
| 12 | # Salesforce Skill |
| 13 | |
| 14 | Use the Salesforce CLI (`sf`) to interact with Salesforce orgs. The CLI must be authenticated before use. Always add `--json` for structured output. |
| 15 | |
| 16 | If the `sf` binary is not available, stop and ask the user to install the Salesforce CLI using the repo's declared install metadata or the official Salesforce CLI guide. After the CLI is available, authenticate with `sf org login web` before touching org data. |
| 17 | |
| 18 | ## Safety Boundaries |
| 19 | |
| 20 | Do not create, update, delete, deploy, or execute Apex without explicit user confirmation. |
| 21 | Do not reveal access tokens, auth URLs, refresh tokens, or verbose org-display output in chat. |
| 22 | Do not export data to files unless the user asked for a saved artifact or bulk workflow. |
| 23 | Do not target a production org by default when sandbox or staging access is available. |
| 24 | |
| 25 | ## Authentication and Org Management |
| 26 | |
| 27 | ### Log in (opens browser) |
| 28 | |
| 29 | sf org login web --alias my-org |
| 30 | |
| 31 | |
| 32 | Other login methods: |
| 33 | |
| 34 | # JWT-based login (CI/automation) |
| 35 | sf org login jwt --client-id <consumer-key> --jwt-key-file server.key --username [email protected] --alias my-org |
| 36 | |
| 37 | # Login with an existing access token |
| 38 | sf org login access-token --instance-url https://mycompany.my.salesforce.com |
| 39 | |
| 40 | # Login via SFDX auth URL (from a file) |
| 41 | sf org login sfdx-url --sfdx-url-file authUrl.txt --alias my-org |
| 42 | |
| 43 | |
| 44 | ### Manage orgs |
| 45 | |
| 46 | # List all authenticated orgs |
| 47 | sf org list --json |
| 48 | |
| 49 | # Display info about the default org (access token, instance URL, username) |
| 50 | sf org display --json |
| 51 | |
| 52 | # Display info about a specific org |
| 53 | sf org display --target-org my-org --json |
| 54 | |
| 55 | # Display with SFDX auth URL (sensitive - contains refresh token) |
| 56 | sf org display --target-org my-org --verbose --json |
| 57 | |
| 58 | # Open org in browser |
| 59 | sf org open |
| 60 | sf org open --target-org my-org |
| 61 | |
| 62 | # Log out |
| 63 | sf org logout --target-org my-org |
| 64 | |
| 65 | |
| 66 | ### Configuration and aliases |
| 67 | |
| 68 | # Set default target org |
| 69 | sf config set target-org my-org |
| 70 | |
| 71 | # List all config variables |
| 72 | sf config list |
| 73 | |
| 74 | # Get a specific config value |
| 75 | sf config get target-org |
| 76 | |
| 77 | # Set an alias |
| 78 | sf alias set [email protected] |
| 79 | |
| 80 | # List aliases |
| 81 | sf alias list |
| 82 | |
| 83 | |
| 84 | ## Querying Data (SOQL) |
| 85 | |
| 86 | Standard SOQL queries via the default API: |
| 87 | |
| 88 | # Basic query |
| 89 | sf data query --query "SELECT Id, Name, Email FROM Contact LIMIT 10" --json |
| 90 | |
| 91 | # WHERE clause |
| 92 | sf data query --query "SELECT Id, Name, Amount, StageName FROM Opportunity WHERE StageName = 'Closed Won'" --json |
| 93 | |
| 94 | # Relationship queries (parent-to-child) |
| 95 | sf data query --query "SELECT Id, Name, (SELECT LastName, Email FROM Contacts) FROM Account LIMIT 5" --json |
| 96 | |
| 97 | # Relationship queries (child-to-parent) |
| 98 | sf data query --query "SELECT Id, Name, Account.Name FROM Contact" --json |
| 99 | |
| 100 | # LIKE for text search |
| 101 | sf data query --query "SELECT Id, Name FROM Account WHERE Name LIKE '%Acme%'" --json |
| 102 | |
| 103 | # Date filtering |
| 104 | sf data query --query "SELECT Id, Name, CreatedDate FROM Lead WHERE CreatedDate = TODAY" --json |
| 105 | |
| 106 | # ORDER BY + LIMIT |
| 107 | sf data query --query "SELECT Id, Name, Amount FROM Opportunity ORDER BY Amount DESC LIMIT 20" --json |
| 108 | |
| 109 | # Include deleted/archived records |
| 110 | sf data query --query "SELECT Id, Name FROM Account" --all-rows --json |
| 111 | |
| 112 | # Query from a file |
| 113 | sf data query --file query.soql --json |
| 114 | |
| 115 | # Tooling API queries (metadata objects like ApexClass, ApexTrigger) |
| 116 | sf data query --query "SELECT Id, Name, Status FROM ApexClass" --use-tooling-api --json |
| 117 | |
| 118 | # Output to CSV file |
| 119 | sf data query --query "SELECT Id, Name, Email FROM Contact" --result-format csv --output-file contacts.csv |
| 120 | |
| 121 | # Target a specific org |
| 122 | sf data query --query "SELECT Id, Name FROM Account" --target-org my-org --json |
| 123 | |
| 124 | |
| 125 | For queries returning more than 10,000 records, use Bulk API instead: |
| 126 | |
| 127 | sf data export bulk --query "SELECT Id, Name, Email FROM Contact" --output-file contacts.csv --result-format csv --wait 10 |
| 128 | sf data export bulk --query "SELECT Id, Name FROM Account" --output-file accounts.json --result-format json --wait 10 |
| 129 | |
| 130 | |
| 131 | ## Text Search (SOSL) |
| 132 | |
| 133 | SOSL searches across multiple objects at once: |
| 134 | |
| 135 | # Search for text across objects |
| 136 | sf data search --query "FIND {John Smith} IN ALL FIELDS RETURNING Contact(Name, Email), Lead(Name, Email)" --json |
| 137 | |
| 138 | # Search in name fields only |
| 139 | sf data search --query "FIND {Acme} IN NAME FIELDS RETURNING Account(Name, Industry), Contact(Name)" --json |
| 140 | |
| 141 | # Search from a file |
| 142 | sf data search --file search.sosl --json |
| 143 | |
| 144 | # Output to CSV |
| 145 | sf data search --query "FIND {test} RETURNING Contact(Name)" --result-format csv |
| 146 | |
| 147 | |
| 148 | ## Single Record Operations |
| 149 | |
| 150 | ### Get a record |
| 151 | |
| 152 | # By record ID |
| 153 | sf data get record --sobject Contact --record-id 003XXXXXXXXXXXX --json |
| 154 | |
| 155 | # By field match (WHERE-like) |
| 156 | sf data get record --sobject Account --where "Name=Acme" --json |
| 157 | |
| 158 | # By multiple fields (values with spaces need single quotes) |
| 159 | sf data get record --sobject Account --where "Name='Universal Containers' Phone='(123) 456-7890'" --json |
| 160 | |
| 161 | |
| 162 | ### Create a record (confirm with user first) |
| 163 | |
| 164 | sf data create record --sobject Contact --values "FirstName='Jane' LastName='Doe' Email='[email protected]'" --json |
| 165 | |
| 166 | sf data create record --sobject Account --values "Name='New Company' Website=www.example.com Industry='Technology'" --json |
| 167 | |
| 168 | # Tooling API object |
| 169 | sf data create record --sobject TraceFlag --use-tooling-api --values "DebugLevelId=7dl... LogType=CLASS_TRACING" --json |
| 170 | |
| 171 | |
| 172 | ### Update a record (confirm with user first) |
| 173 | |
| 174 | # By ID |
| 175 | sf data update record --sobject Contact --record-id 003XXXXXXXXXXXX --values "Email='[email protected]'" --json |
| 176 | |
| 177 | # By field match |
| 178 | sf data update record --sobject Account --where "Name='Old Acme'" --values "Name='New Acme'" --json |
| 179 | |
| 180 | # Multiple fields |
| 181 | sf data update record --sobject Account --record-id 001XXXXXXXXXXXX --values "Name='Acme III' Website=www.example.com" --json |
| 182 | |
| 183 | |
| 184 | ### Delete a record (require explicit user confirmation) |
| 185 | |
| 186 | # By ID |
| 187 | sf data delete record --sobject Account --record-id 001XXXXXXXXXXXX --json |
| 188 | |
| 189 | # By field match |
| 190 | sf data delete record --sobject Account --where "Name=Acme" --json |
| 191 | |
| 192 | |
| 193 | ## Bulk Data Operations (Bulk API 2.0) |
| 194 | |
| 195 | For large datasets (thousands to millions of records): |
| 196 | |
| 197 | ### Bulk export |
| 198 | |
| 199 | # Export to CSV |
| 200 | sf data export bulk --query "SELECT Id, Name, Email FROM Contact" --output-file contacts.csv --result-format csv --wait 10 |
| 201 | |
| 202 | # Export to JSON |
| 203 | sf data export bulk --query "SELECT Id, Name FROM Account" --output-file accounts.json --result-format json --wait 10 |
| 204 | |
| 205 | # Include soft-deleted records |
| 206 | sf data export bulk --query "SELECT Id, Name FROM Account" --output-file accounts.csv --result-format csv --all-rows --wait 10 |
| 207 | |
| 208 | # Resume a timed-out export |
| 209 | sf data export resume --job-id 750XXXXXXXXXXXX --json |
| 210 | |
| 211 | |
| 212 | ### Bulk import |
| 213 | |
| 214 | # Import from CSV |
| 215 | sf data import bulk --file accounts.csv --sobject Account --wait 10 |
| 216 | |
| 217 | # Resume a timed-out import |
| 218 | sf data import resume --job-id 750XXXXXXXXXXXX --json |
| 219 | |
| 220 | |
| 221 | ### Bulk upsert |
| 222 | |
| 223 | sf data upsert bulk --file contacts.csv --sobject Contact --external-id Email --wait 10 |
| 224 | |
| 225 | |
| 226 | ### Bulk delete |
| 227 | |
| 228 | # Delete records listed in CSV (CSV must have an Id column) |
| 229 | sf data delete bulk --file records-to-delete.csv --sobject Contact --wait 10 |
| 230 | |
| 231 | |
| 232 | ### Tree export/import (for related records) |
| 233 | |
| 234 | # Export with relationships into JSON tree format |
| 235 | sf data export tree --query "SELECT Id, Name, (SELECT Name, Email FROM Contacts) FROM Account" --json |
| 236 | |
| 237 | # Export with a plan file (for multiple objects) |
| 238 | sf data export tree --query "SELECT Id, Name FROM Account" --plan --output-dir export-data |
| 239 | |
| 240 | # Import from tree JSON files |
| 241 | sf data import tree --files Account.json,Contact.json |
| 242 | |
| 243 | # Import using a plan definition file |
| 244 | sf data import tree --plan Account-Contact-plan.json |
| 245 | |
| 246 | |
| 247 | ## Schema Inspection |
| 248 | |
| 249 | |
| 250 | # Describe an object (fields, relationships, picklist values) |
| 251 | sf sobject describe --sobject Account --json |
| 252 | |
| 253 | # Describe a custom object |
| 254 | sf sobject describe --sobject MyCustomObject__c --json |
| 255 | |
| 256 | # Describe a Tooling API object |
| 257 | sf sobject describe --sobject ApexClass --use-tooling-api --json |
| 258 | |
| 259 | # List all objects |
| 260 | sf sobject list --json |
| 261 | |
| 262 | # List only custom objects |
| 263 | sf sobject list --sobject custom --json |
| 264 | |
| 265 | # List only standard objects |
| 266 | sf sobject list --sobject standard --json |
| 267 | |
| 268 | |
| 269 | ## Execute Apex Code |
| 270 | |
| 271 | |
| 272 | # Execute Apex from a file |
| 273 | sf apex run --file script.apex --json |
| 274 | |
| 275 | # Run interactively (type code, press Ctrl+D to execute) |
| 276 | sf apex run |
| 277 | |
| 278 | # Run Apex tests |
| 279 | sf apex run test --test-names MyTestClass --json |
| 280 | |
| 281 | # Get test results |
| 282 | sf apex get test --test-run-id 707XXXXXXXXXXXX --json |
| 283 | |
| 284 | # View Apex logs |
| 285 | sf apex list log --json |
| 286 | sf apex get log --log-id 07LXXXXXXXXXXXX |
| 287 | |
| 288 | |
| 289 | ## REST API (Advanced) |
| 290 | |
| 291 | Make arbitrary authenticated REST API calls: |
| 292 | |
| 293 | # GET request |
| 294 | sf api request rest 'services/data/v62.0/limits' --json |
| 295 | |
| 296 | # List API versions |
| 297 | sf api request rest '/services/data/' --json |
| 298 | |
| 299 | # Create a record via REST |
| 300 | sf api request rest '/services/data/v62.0/sobjects/Account' --method POST --body '{"Name":"REST Account","Industry":"Technology"}' --json |
| 301 | |
| 302 | # Update a record via REST (PATCH) |
| 303 | sf api request rest '/services/data/v62.0/sobjects/Account/001XXXXXXXXXXXX' --method PATCH --body '{"BillingCity":"San Francisco"}' --json |
| 304 | |
| 305 | # GraphQL query |
| 306 | sf api request graphql --body '{"query":"{ uiapi { query { Account { edges { node { Name { value } } } } } } }"}' --json |
| 307 | |
| 308 | # Custom headers |
| 309 | sf api request rest '/services/data/v62.0/limits' --header 'Accept: application/xml' |
| 310 | |
| 311 | # Save response to file |
| 312 | sf api request rest '/services/data/v62.0/limits' --stream-to-file limits.json |
| 313 | |
| 314 | |
| 315 | ## Metadata Deployment and Retrieval |
| 316 | |
| 317 | |
| 318 | # Deploy metadata to an org |
| 319 | sf project deploy start --source-dir force-app --json |
| 320 | |
| 321 | # Deploy specific metadata components |
| 322 | sf project deploy start --metadata ApexClass:MyClass --json |
| 323 | |
| 324 | # Retrieve metadata from an org |
| 325 | sf project retrieve start --metadata ApexClass --json |
| 326 | |
| 327 | # Check deploy status |
| 328 | sf project deploy report --job-id 0AfXXXXXXXXXXXX --json |
| 329 | |
| 330 | # Generate a new Salesforce DX project |
| 331 | sf project generate --name my-project |
| 332 | |
| 333 | # List metadata components in the org |
| 334 | sf project list ignored --json |
| 335 | |
| 336 | |
| 337 | ## Diagnostics |
| 338 | |
| 339 | |
| 340 | # Run CLI diagnostics |
| 341 | sf doctor |
| 342 | |
| 343 | # Check CLI version |
| 344 | sf version |
| 345 | |
| 346 | # See what is new |
| 347 | sf whatsnew |
| 348 | |
| 349 | |
| 350 | ## Common SOQL Patterns |
| 351 | |
| 352 | |
| 353 | -- Count records |
| 354 | SELECT COUNT() FROM Contact WHERE AccountId = '001XXXXXXXXXXXX' |
| 355 | |
| 356 | -- Aggregate query |
| 357 | SELECT StageName, COUNT(Id), SUM(Amount) FROM Opportunity GROUP BY StageName |
| 358 | |
| 359 | -- Date literals |
| 360 | SELECT Id, Name FROM Lead WHERE CreatedDate = LAST_N_DAYS:30 |
| 361 | |
| 362 | -- Subquery (semi-join) |
| 363 | SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Email LIKE '%@acme.com') |
| 364 | |
| 365 | -- Polymorphic lookup |
| 366 | SELECT Id, Who.Name, Who.Type FROM Task WHERE Who.Type = 'Contact' |
| 367 | |
| 368 | -- Multiple WHERE conditions |
| 369 | SELECT Id, Name, Amount FROM Opportunity WHERE Amount > 10000 AND StageName != 'Closed Lost' AND CloseDate = THIS_QUARTER |
| 370 | |
| 371 | |
| 372 | ## Guardrails |
| 373 | |
| 374 | **Always use `--json`** for structured, parseable output. |
| 375 | **Never create, update, or delete records** without explicit user confirmation. Describe the operation and ask before executing. |
| 376 | **Never delete records** unless the user explicitly requests it and confirms the specific record(s). |
| 377 | **Never bulk delete or bulk import** without user reviewing the file/query and confirming. |
| 378 | Use `LIMIT` on queries to avoid excessive data. Start with `LIMIT 10` and increase if the user needs more. |
| 379 | For queries over 10,000 records, use `sf data export bulk` instead of `sf data query`. |
| 380 | When the user asks to "find" or "search" a single object, use SOQL `WHERE ... LIKE '%term%'`. When searching across multiple objects, use SOSL via `sf data search`. |
| 381 | Use `--target-org <alias>` when the user has multiple orgs; ask which org if ambiguous. |
| 382 | If authentication fails or a session expires, guide the user through `sf org login web`. |
| 383 | Bulk API 2.0 has SOQL limitations (no aggregate functions like `COUNT()`). Use standard `sf data query` for those. |
| 384 | When describing objects (`sf sobject describe`), the JSON output can be very large. Summarize the key fields, required fields, and relationships for the user rather than dumping the raw output. |
| 385 |
Discussion
Browse more free Claude skills or everything in Development.