| name | sf-cli-deployment |
| description | Expert guidance for Salesforce CLI (sf) development deployments. Use this skill when deploying code during development, testing changes in sandboxes/scratch orgs, or when the user mentions sf CLI, deployments, or org operations. Focused on iterative development workflow. |
Salesforce CLI Development Deployment Guide
Core Principles
CRITICAL: Use the modern sf CLI (not legacy sfdx) for all Salesforce operations. This skill focuses on development deployments for iterative coding workflows, not production migrations or CI/CD pipelines.
Understanding Deployment Commands
❌ CRITICAL MISTAKE TO AVOID
NEVER use deploy start to check deployment status!
sf project deploy start --source-dir force-app
sf project deploy report --job-id <deployment-id>
sf project deploy resume --job-id <deployment-id> --wait 30
Deployment Command Breakdown
Starting a deployment:
sf project deploy start --source-dir force-app
Checking deployment status:
sf project deploy report --job-id 0Af1234567890ABCD
Waiting for completion:
sf project deploy resume --job-id 0Af1234567890ABCD --wait 30
Canceling a deployment:
sf project deploy cancel --job-id 0Af1234567890ABCD
Modern sf CLI Commands
Always use sf (not legacy sfdx):
sf project deploy start --source-dir force-app
sf org login web --alias mydev
sf data query --query "SELECT Id, Name FROM Account"
sf org open
sfdx force:source:deploy -p force-app
sfdx force:auth:web:login -a mydev
Development Deployment Workflows
Quick Iteration Loop (LWC, Visualforce, Aura)
For front-end components that need testing in the org:
sf project deploy start --source-dir force-app/main/default/lwc/myComponent
sf org open --target-org mydev
No tests needed - Front-end components don't require Apex tests.
Apex Deployment with Test Options
When deploying Apex classes or triggers, ASK the user about testing:
Prompt: "Would you like to run tests with this Apex deployment?"
Option 1: No tests (fastest - 1-2 minutes)
sf project deploy start \
--source-dir force-app \
--test-level NoTestRun
Option 2: Specific test classes (moderate - 2-10 minutes)
sf project deploy start \
--source-dir force-app \
--test-level RunSpecifiedTests \
--tests AccountServiceTest \
--tests ContactTriggerHandlerTest
Option 3: All local tests (slow - 15-60+ minutes)
⚠️ WARN USER FIRST:
Running all local tests can take a long time (15-60+ minutes depending on org size).
Continue with RunLocalTests? (yes/no)
If user confirms:
DEPLOY_ID=$(sf project deploy start \
--source-dir force-app \
--test-level RunLocalTests \
--json | jq -r '.result.id')
echo "Deployment ID: $DEPLOY_ID"
echo "⏳ Running all tests... this may take 15-60+ minutes"
echo "💡 To cancel: sf project deploy cancel --job-id $DEPLOY_ID"
sf project deploy resume --job-id $DEPLOY_ID --wait 60
Monitoring Long-Running Deployments
For deployments that take time:
sf project deploy report --job-id <deployment-id>
sf project deploy resume --job-id <deployment-id> --wait 30
sf project deploy cancel --job-id <deployment-id>
Status indicators:
InProgress - Still running
Succeeded - Completed successfully
Failed - Deployment failed
Canceled - User canceled deployment
Deployment Scenarios
Deploy Specific Components
sf project deploy start \
--source-dir force-app/main/default/lwc/accountList
sf project deploy start \
--metadata ApexClass:AccountService \
--metadata ApexClass:AccountServiceTest
sf project deploy start \
--source-dir force-app/main/default/objects/CustomObject__c
sf project deploy start \
--metadata ApexClass:AccountService \
--metadata ApexTrigger:AccountTrigger \
--test-level NoTestRun
Deploy Entire Project
sf project deploy start --source-dir force-app
sf project deploy start \
--source-dir force-app \
--test-level RunLocalTests
Preview What Will Deploy
sf project deploy start --source-dir force-app --dry-run
sf project deploy preview --source-dir force-app
Org Management
Authentication
sf org login web --alias mydev --instance-url https://test.salesforce.com
sf org login web --alias prod --instance-url https://login.salesforce.com
sf org login web --alias myorg --instance-url https://mycompany.my.salesforce.com
sf org list
sf org open --target-org mydev
sf config set target-org=mydev
Scratch Orgs
sf org create scratch \
--definition-file config/project-scratch-def.json \
--alias scratch-dev \
--duration-days 7 \
--set-default
sf project deploy start --source-dir force-app
sf org open
sf org delete scratch --target-org scratch-dev --no-prompt
Running Tests Separately
After deploying without tests, run tests independently:
sf apex run test \
--tests AccountServiceTest \
--result-format human \
--code-coverage
sf apex run test \
--tests AccountServiceTest,ContactHandlerTest \
--result-format human
sf apex run test \
--test-level RunLocalTests \
--result-format human \
--code-coverage \
--wait 60
sf apex get test \
--test-run-id <test-run-id> \
--code-coverage \
--result-format human
Post-Deployment Workflow
After Successful Deployment
When deployment succeeds, guide user:
✅ Deployment successful!
Next steps:
1. Test your changes: sf org open --target-org mydev
2. [If git detected] Commit your changes? (yes/no)
If user wants to commit (and git is available):
git status
git add force-app/
git commit -m "Description of changes"
git push origin feature-branch
Retrieving Metadata from Org
Pull changes from org to local project:
sf project retrieve start --metadata ApexClass:AccountService
sf project retrieve start --source-dir force-app
sf project retrieve start --manifest package.xml
sf project retrieve preview
Data Operations
Query Data
sf data query --query "SELECT Id, Name FROM Account LIMIT 10"
sf data query \
--query "SELECT Id, Name, Industry FROM Account" \
--result-format csv > accounts.csv
sf data query --file query.soql
Import/Export Data
sf data export tree \
--query "SELECT Id, Name, (SELECT Id, FirstName FROM Contacts) FROM Account" \
--output-dir data \
--plan
sf data import tree --plan data/plan.json
sf data import csv --file accounts.csv --sobject Account
Common Development Patterns
LWC Development Loop
sf project deploy start \
--source-dir force-app/main/default/lwc/myComponent
sf org open
Apex Development Loop
sf project deploy start \
--metadata ApexClass:MyClass \
--metadata ApexClass:MyClassTest \
--test-level NoTestRun
sf apex run test \
--tests MyClassTest \
--result-format human \
--code-coverage
Custom Object Changes
sf project deploy start \
--source-dir force-app/main/default/objects/MyObject__c
sf org open
Troubleshooting Development Deployments
Deployment Failed
sf project deploy report --job-id <deployment-id> --verbose
Test Failures
sf project deploy report --job-id <deployment-id>
sf apex run test \
--tests FailedTestClass \
--result-format human
sf apex get test --code-coverage --result-format human
Dependency Issues
sf project deploy start --metadata CustomObject
sf project deploy start --metadata CustomField
sf project deploy start --metadata ApexClass
sf project deploy start --metadata ApexTrigger
Long-Running Deployment
sf project deploy report --job-id <deployment-id>
sf project deploy cancel --job-id <deployment-id>
sf project deploy start \
--source-dir force-app \
--test-level NoTestRun
Key Development Reminders
- Use
deploy report to check status - Never use deploy start for status checks
- Cancel long deployments - Use
deploy cancel if needed
- NoTestRun for iteration - Skip tests during rapid development
- Test separately - Run tests after deployment for faster feedback
- Open org to test - Use
sf org open after deployment
- Deploy specific components - Faster than deploying entire project
- Preview before deploy - Use
--dry-run to check what will deploy
- No git requirements - Commit only when ready, not before deployment
- Warn for long tests - Alert user before running all local tests
- Monitor progress - Check status periodically for long deployments
Time Estimates
- LWC/Visualforce deployment: 30 seconds - 2 minutes
- Apex without tests: 1-2 minutes
- Apex with specific tests: 2-10 minutes
- Apex with all local tests: 15-60+ minutes (warn user!)
- Large metadata deployments: 5-15 minutes
Quick Command Reference
Deploy
sf project deploy start --source-dir <dir> - Deploy source
sf project deploy start --metadata <type>:<name> - Deploy specific metadata
sf project deploy start --dry-run - Preview deployment
sf project deploy report --job-id <id> - Check status
sf project deploy resume --job-id <id> - Resume waiting
sf project deploy cancel --job-id <id> - Cancel deployment
Org
sf org login web --alias <name> - Login to org
sf org open - Open org in browser
sf org list - List orgs
sf org display - Show org info
Test
sf apex run test --tests <class> - Run tests
sf apex get test --code-coverage - Get coverage
Data
sf data query --query <soql> - Query data
sf org open - Open org to test UI changes
Focus: Development iteration and testing
NOT included: Production deployments, CI/CD, environment migrations
Created for: Claude Code
Last Updated: November 2025