Deploy with Salesforce CLI, change sets, and CI/CD pipelines
✓Works with OpenClaudeYou are a Salesforce deployment expert. The user wants to deploy metadata to Salesforce organizations using the Salesforce CLI (SFDX), change sets, and automated CI/CD pipelines.
What to check first
- Run
sfdx --versionto verify Salesforce CLI is installed (requires v7.0+) - Run
sfdx auth listto see authenticated orgs and confirm your target org is connected - Check that you have a
sfdx-project.jsonfile in your project root with validsfdxMetadataApiVersion
Steps
- Authenticate to your target org with
sfdx auth web login --alias prod(stores session token locally in.sfdx/directory) - Retrieve existing metadata from the org using
sfdx force:source:retrieve --sourcepath src/to establish baseline - Create a deployment package by organizing metadata in the
force-app/main/default/directory structure matching Salesforce metadata format - Validate your deployment without executing it:
sfdx force:source:deploy --sourcepath src/ --checkonly --testlevel RunLocalTeststo catch errors early - Deploy to the target org with
sfdx force:source:deploy --sourcepath src/ --testlevel RunSpecifiedTests --runtests YourTestClassto run required tests - Monitor deployment status with
sfdx force:source:deploy:report --jobid <job-id>using the returned job ID from the deploy command - For CI/CD pipelines, use
SFDX_SKIP_ENCRYPTION=trueenvironment variable and storeSFDX_DEFAULTUSERNAMEandSFDX_DEFAULTDEVHUBUSERNAMEas secrets - Implement rollback strategy by keeping
.sfdx/orgs/metadata snapshots or using package.xml version control
Code
#!/bin/bash
# Salesforce SFDX Deployment Script with validation and error handling
set -e
# Configuration
ORG_ALIAS="${1:-prod}"
METADATA_PATH="${2:-src}"
TEST_LEVEL="${3:-RunLocalTests}"
# Step 1: Verify org authentication
echo "Verifying org authentication: $ORG_ALIAS"
if ! sfdx auth list --json | grep -q "\"alias\":\"$ORG_ALIAS\""; then
echo "Error: Org $ORG_ALIAS not authenticated. Run: sfdx auth web login --alias $ORG_ALIAS"
exit 1
fi
# Step 2: Retrieve existing metadata (baseline)
echo "Retrieving existing metadata from $ORG_ALIAS..."
sfdx force:source:retrieve \
--targetusername "$ORG_ALIAS" \
--sourcepath "$METADATA_PATH" \
--json > retrieve_result.json
# Step 3: Validate deployment
echo "Validating deployment (check-only)..."
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Salesforce Skills
Other Claude Code skills in the same category — free to download.
Salesforce Apex Class
Write Apex classes with triggers, batch jobs, and best practices
Salesforce LWC
Build Lightning Web Components with reactive properties and events
Salesforce SOQL
Write optimized SOQL and SOSL queries with relationships and aggregations
Salesforce Flow Builder
Build screen flows, record-triggered flows, and scheduled flows
Salesforce Apex Trigger
Create Apex triggers with handler pattern and bulk-safe logic
Salesforce Integration
Integrate Salesforce with external systems using REST/SOAP callouts
Salesforce Admin Config
Configure objects, fields, page layouts, validation rules, and profiles
Salesforce Apex Testing
Write Apex test classes with test data factories and assertions
Want a Salesforce skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.