sf-deploy
Skill17 starsChanged 9 months agoApache-2.0View on GitHub
Orchestrate Salesforce deployments with dependency resolution, package.xml generation, targeted test execution, error diagnosis, and rollback strategies. Use when asked to deploy code, troubleshoot deployment errors, generate package.xml, set up CI/CD pipelines, or validate deployments. Activate on mentions of "deploy", "deployment", "package.xml", "CI/CD", "GitHub Actions", "validation error", or "deployment failure".
- Installs packages
In this repository19 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- sf-agentforceSkill
- sf-apexSkill
- sf-dataSkill
- sf-debugSkill
- sf-diagramSkill
- sf-docsSkill
- sf-evalSkill
- sf-findSkill
- sf-flowSkill
- sf-integrationSkill
- sf-lwcSkill
- sf-omnistudioSkill
- sf-permissionsSkill
- sf-schemaSkill
- sf-securitySkill
- sf-soqlSkill
- sf-testSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 222
Always validate (--dry-run) before deploying
- Distinctive: line 223
Keep previous version in git — rollback = deploy previous commit
- Distinctive: line 225
Use scratch orgs / sandboxes for testing before production
- Distinctive: line 231
Verify org authentication and connection
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Deployment Orchestrator
You are a Salesforce deployment specialist. Manage multi-step deployments with error handling and dependency resolution.
Deployment Workflow
1. Pre-Deployment Checks
# Verify org connection
sf org display --target-org myOrg
# Check what will be deployed
sf project deploy preview -d force-app/
# Validate without deploying
sf project deploy start -d force-app/ --dry-run --target-org myOrg2. Generate package.xml
# From org (full manifest)
sf project generate manifest --from-org myOrg --output-dir manifest/
# From local source
sf project generate manifest -d force-app/ --output-dir manifest/3. Deployment Order (Dependencies First)
Deploy in this order to avoid dependency failures:
- Custom Objects & Fields — schema must exist before code references it
- Custom Labels & Custom Metadata — referenced by Apex and Flows
- Permission Sets & Custom Permissions — required by bypass logic
- Apex Classes — service classes, selectors, utilities first
- Apex Triggers — depend on handler classes
- Flows — may reference Apex actions
- LWC — may wire to Apex controllers
- Layouts, FlexiPages, Profiles — reference everything above
4. Deploy Commands
# Deploy specific directory
sf project deploy start -d force-app/main/default/classes/ --target-org myOrg
# Deploy with specific tests
sf project deploy start -d force-app/ --test-level RunSpecifiedTests --tests MyClassTest,MyOtherClassTest --target-org myOrg
# Deploy with all tests (production)
sf project deploy start -d force-app/ --test-level RunLocalTests --target-org myOrg
# Deploy specific metadata
sf project deploy start -m ApexClass:MyClass,ApexClass:MyClassTest --target-org myOrg
# Quick deploy (after successful validation)
sf project deploy quick --job-id <validationId> --target-org myOrg5. Delta Deployments
For CI/CD, deploy only changed files:
# Using sfdx-git-delta
sfdx sgd:source:delta --from origin/main --to HEAD --output delta/
sf project deploy start -d delta/force-app/ --target-org myOrgScratch Org Workflows
# Create scratch org from definition file
sf org create scratch -f config/project-scratch-def.json -a scratch1 -d 30
# Create from org shape (clones source org config)
sf org create scratch --source-org prodOrg -a scratch1
# Delete scratch org
sf org delete scratch -o scratch1 --no-promptPackage Development
# Create unlocked package
sf package create --name "My Package" --package-type Unlocked --path force-app
# Create package version
sf package version create --package "My Package" --installation-key test1234 --wait 10
# Install package in target org
sf package install --package 04t... --target-org myOrg --wait 10- Unlocked Packages: Org-independent, no namespace lock, editable after install
- 2GP Managed: Namespace-locked, IP protection, AppExchange distribution
Destructive Changes
<!-- destructiveChangesPost.xml — deletes AFTER deployment -->
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>OldClass</members>
<name>ApexClass</name>
</types>
<version>62.0</version>
</Package>destructiveChangesPre.xml— deletes BEFORE deploy (remove dependencies first)destructiveChangesPost.xml— deletes AFTER deploy (clean up replaced components)- Deploy with:
sf project deploy start -d force-app/ --post-destructive-changes destructiveChangesPost.xml
Authentication Methods
| Method | Use Case | Command |
| Web Login | Interactive / dev | sf org login web |
| JWT Bearer | CI/CD (headless) | sf org login jwt --client-id ... --jwt-key-file ... |
| SFDX Auth URL | CI/CD (simpler) | sf org login sfdx-url --sfdx-url-file authUrl.txt |
| Device Flow | Headless (no cert) | sf org login device |
Salesforce Code Analyzer
# Run static analysis
sf scanner run --target force-app/ --format csv --outfile results.csv
# Run with specific rules
sf scanner run --target force-app/ --category "Security,Best Practices"Test Level Guide
| Level | When | Command Flag |
| NoTestRun | Non-prod, metadata-only | --test-level NoTestRun |
| RunSpecifiedTests | Known affected tests | --test-level RunSpecifiedTests --tests MyTest |
| RunLocalTests | Production deploy | --test-level RunLocalTests |
| RunAllTestsInOrg | Full validation | --test-level RunAllTestsInOrg |
Error Diagnosis
Common Deployment Errors
| Error | Cause | Fix |
Entity not found: CustomObject__c | Missing dependency | Deploy custom object first |
Dependent class is invalid | Compile error in dependency | Fix dependent class first |
Code coverage is below 75% | Insufficient tests | Run sf-test skill to generate tests |
Component not found: c:myComponent | Missing LWC dependency | Deploy LWC before FlexiPage |
Test failure: System.AssertException | Test expecting wrong data | Fix test assertions |
FIELD_CUSTOM_VALIDATION_EXCEPTION | Validation rule blocking test data | Update test data to pass validation |
INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY | Sharing/permission issue | Check profile/permission set deployment |
Diagnosing Failures
# Check deploy status
sf project deploy report --job-id <jobId>
# Get detailed error info
sf project deploy resume --job-id <jobId>CI/CD Pipeline (GitHub Actions)
name: Salesforce CI/CD
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
validate:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install @salesforce/cli -g
- name: Authenticate
run: sf org login jwt --client-id ${{ secrets.SF_CLIENT_ID }} --jwt-key-file server.key --username ${{ secrets.SF_USERNAME }} --instance-url ${{ secrets.SF_INSTANCE_URL }} --alias ci-org
- name: Validate
run: sf project deploy start -d force-app/ --dry-run --test-level RunLocalTests --target-org ci-org
deploy:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm install @salesforce/cli -g
- name: Authenticate
run: sf org login jwt --client-id ${{ secrets.SF_CLIENT_ID }} --jwt-key-file server.key --username ${{ secrets.SF_USERNAME }} --instance-url ${{ secrets.SF_INSTANCE_URL }} --alias prod-org
- name: Deploy
run: sf project deploy start -d force-app/ --test-level RunLocalTests --target-org prod-orgGotchas
- Profiles cause merge conflicts — prefer Permission Sets for deployable permissions
- Destructive changes cannot be rolled back — always validate first
- Quick deploy validations expire after 10 days
- Source tracking resets when scratch org expires
- Package dependencies must be installed in dependency order
- API version mismatches between components can cause silent deployment failures
RunLocalTestsskips managed package tests —RunAllTestsInOrgincludes them- Sandbox refresh does not preserve manual configuration changes
Rollback Strategy
Salesforce has no native rollback. Mitigation:
- Always validate (
--dry-run) before deploying - Keep previous version in git — rollback = deploy previous commit
- For destructive changes, prepare
destructiveChangesPost.xml - Use scratch orgs / sandboxes for testing before production
References
- Deploy Patterns — scratch orgs, packages, destructive changes, sandbox types, Code Analyzer, sfdx-git-delta, auth methods, DevOps Center
Workflow
- Verify org authentication and connection
- Analyze what needs to be deployed
- Resolve dependencies and determine deploy order
- Validate deployment (dry-run)
- Deploy with appropriate test level
- Monitor deployment status
- Diagnose and fix any errors
- Verify deployment success
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

