Salesforce Deployment and CI/CD: Change Sets, Salesforce CLI, Lifecycle Center and Pipelines
Master Salesforce deployment strategies and Continuous Integration/Continuous Delivery (CI/CD) practices. Learn to move changes efficiently and reliably across environments, ensuring quality and accelerating development cycles.
How do you set up CI/CD for Salesforce?
Salesforce CI/CD keeps metadata in Git and lets a pipeline such as GitHub Actions check every change. On each pull request the pipeline runs sf project deploy validate with Apex tests against the target org; after approval, sf project deploy quick releases the validated change. Change sets still work for small teams but have no version history or automation.
- Salesforce CLI (sf) is the current command-line tool; the older sfdx commands are deprecated.
- Production deployments that include Apex need at least 75% code coverage, and every trigger needs some coverage.
- Test levels include NoTestRun, RunSpecifiedTests, RunLocalTests and RunAllTestsInOrg.
- Lifecycle Center, previously Next-Generation DevOps Center, is Salesforce's Git-backed release tool; the DevOps Center managed package loses support on 4 June 2027.
- Authenticate pipelines with the JWT bearer flow and a connected or external client app, not a stored password.
1. Introduction to Deployment & CI/CD
In Salesforce development, moving changes from a development environment (like a Sandbox) to a testing environment, and eventually to production, is a critical and often complex process. This is known as Deployment. As development teams grow and changes become more frequent, manual deployment processes become slow, error-prone, and unsustainable.
This is where Continuous Integration (CI) and Continuous Delivery/Deployment (CD) come into play. CI/CD automates build, test, and delivery steps. Production deployment may require approval.
Why are Deployment & CI/CD Important?
- Speed: Automate repetitive tasks, accelerating the delivery of new features and bug fixes.
- Reliability: Reduce human error and ensure consistency in deployments.
- Quality: Integrate automated testing, static code analysis, and security checks early in the development cycle.
- Collaboration: Facilitate better collaboration among developers by frequently merging code.
- Visibility: Provide clear visibility into the status of deployments and potential issues.
- Recovery Planning: Use versioned changes and a tested recovery plan to address deployment issues.
This module will guide you through various Salesforce deployment methods and introduce the core concepts, tools, and best practices of CI/CD tailored for the Salesforce platform.
2. Salesforce Deployment Methods
Salesforce offers several ways to deploy metadata (code, configurations, custom objects, etc.) between environments. The choice of method often depends on the complexity of the changes, team size, and the level of automation desired.
a. Change Sets
- Description: A declarative, point-and-click tool within the Salesforce UI for moving metadata between related organizations (e.g., Sandbox to Production).
- Pros:
- Easy to use for administrators.
- No external tools or command-line interface required.
- Built-in validation and deployment.
- Cons:
- Cannot retrieve or deploy all metadata types.
- Difficult to manage for large or complex projects.
- No version control integration.
- Manual process, prone to human error.
- Cannot deploy between unrelated orgs.
- Best For: Small, simple, infrequent deployments by administrators.
b. Salesforce CLI (SFDX)
- Description: A powerful command-line interface that allows developers to interact with their Salesforce orgs, retrieve metadata, deploy changes, run tests, and manage scratch orgs. It's the cornerstone of the Salesforce DX development model.
- Pros:
- Metadata support varies by type, API version, and operation. Consult Metadata Coverage before planning a deployment.
- Integrates well with version control systems (Git).
- Enables automation through scripting.
- Supports scratch orgs for isolated development.
- Can deploy supported metadata to authorized target orgs, subject to compatibility, permissions, features, and dependencies.
- Cons:
- Requires command-line proficiency.
- Steeper learning curve for administrators.
- Best For: Developer-centric teams, CI/CD pipelines, complex deployments, source-driven development.
# Retrieve metadata
sf project retrieve start -m "ApexClass:MyClass,CustomObject:MyObject__c"
# Deploy metadata and wait for a result
sf project deploy start -d force-app/main/default -o myProductionOrg --wait 10
# Run Apex tests and wait for a result
sf apex run test -l RunLocalTests -o myProductionOrg --wait 10
If a deployment is still running when the wait ends, check its final status with sf project deploy report or resume it. If the test run is still incomplete, poll with sf apex get test --test-run-id <test-run-id> --target-org myProductionOrg. A pipeline must gate on the final successful result, not the receipt of a job ID. See the Apex test command reference.
c. Ant Migration Tool
- Description: A Java-based command-line utility that uses Apache Ant to retrieve and deploy Salesforce metadata. It was popular for programmatic deployments before SFDX.
- Pros:
- Metadata support varies by type, API version, and operation. Consult Metadata Coverage before planning a deployment.
- Can be scripted for automation.
- Cons:
- Requires Java and Ant setup.
- XML-based configuration can be verbose.
- Retired in Spring 2024 and unsupported, although it can still function. See the Ant Migration Tool guidance.
- Migration: Migrate legacy Ant pipelines to the supported Salesforce CLI.
d. Managed & Unmanaged Packages
- Description: Packages are containers for Salesforce components that can be distributed to other orgs.
- Unmanaged Packages: Used for distributing open-source projects or templates. Components are fully editable after installation.
- Managed Packages: Used to distribute applications, including AppExchange products. They provide upgradeability and component-specific protection and editability rules.
- Unlocked Packages: Organize supported metadata into versioned, upgradeable packages for modular development and deployment.
- Pros:
- Easy distribution and installation.
- Good for sharing reusable components or entire applications.
- Cons:
- Choose a package type for the distribution model; managed second-generation packages and unlocked packages can support iterative releases.
- Versioning and upgrade complexities for managed packages.
- Best For: Distributing solutions to multiple customers/orgs, AppExchange products.
How do you validate and test a production deployment?
Validate the exact deployment against the target production org, then use a successful validation for a quick deploy when it remains eligible. Record the validation job ID and check its final status; if the validation expires or the changes require a new validation, validate again. Select the deployment test level for the change and target org. Local or all-org tests provide broader feedback, while specified tests reduce scope but have different coverage requirements. Include Flow tests where relevant; sf logic run test can run Apex and Flow tests together. Require final passing results and review coverage before release. See the quick deploy reference and test reference.
3. Understanding CI/CD
Continuous Integration (CI) and Continuous Delivery (CD) are methodologies that aim to improve software quality and delivery speed by automating various stages of the software development lifecycle.
a. Continuous Integration (CI)
- Concept: Developers frequently merge their code changes into a central shared repository. Each merge triggers an automated build and test process.
- Goals:
- Detect integration errors early.
- Reduce merge conflicts.
- Maintain a consistently working codebase.
- Provide rapid feedback to developers.
- Key Steps in Salesforce CI:
- Developer commits changes to a feature branch in Git.
- Feature branch is merged into a main integration branch (e.g.,
develop). - CI server detects the merge.
- Automated process retrieves metadata from the integration branch.
- Deploys metadata to a CI Sandbox (or scratch org).
- Runs Apex tests and potentially static code analysis.
- Notifies the team of success or failure.
b. Continuous Delivery (CD)
- Concept: An extension of CI where code that has passed all automated tests is always in a deployable state. It automates the release process to various environments (UAT, Staging, Production).
- Goals:
- Ensure software is always ready for release.
- Reduce risk of deployments.
- Enable rapid, reliable releases.
- Continuous Deployment: Every change that passes all stages is automatically deployed to production without manual intervention. Less common in Salesforce due to org compliance requirements.
- Key Steps in Salesforce CD:
- Code passes CI checks.
- Automated deployment to a UAT Sandbox.
- Automated or manual execution of UAT tests.
- If successful, automated deployment to Staging/Pre-Production.
- Finally, automated or manual deployment to Production.
4. CI/CD Tools for Salesforce
A variety of tools can be used to implement CI/CD pipelines for Salesforce. These tools orchestrate the steps of retrieving, validating, deploying, and testing metadata.
a. Generic CI/CD Platforms
- Jenkins: An open-source automation server. Highly customizable with a vast plugin ecosystem. Requires self-hosting and maintenance.
- GitLab CI/CD: Built directly into GitLab, offering a comprehensive solution for SCM and CI/CD. Uses a
.gitlab-ci.ymlfile for pipeline definition. - GitHub Actions: Integrated CI/CD within GitHub. Uses YAML workflows to automate tasks directly from your repository.
- Azure DevOps: A suite of development services including Azure Pipelines. Offers robust build, test, and release management integrated with Azure services.
- Bitbucket Pipelines: CI/CD integrated with Bitbucket repositories, configured via a
bitbucket-pipelines.ymlfile.
These tools can use Salesforce CLI commands to interact with Salesforce orgs. Existing integrations may still use the retired, unsupported Ant Migration Tool.
How do you validate Salesforce changes with GitHub Actions?
Add a workflow that logs in with the JWT bearer flow and runs sf project deploy validate on every pull request. The validation compiles your changes and runs Apex tests in the target org without saving anything. Store the client ID, username and private key as repository secrets, never in the repository.
name: Validate Salesforce changes
on:
pull_request:
branches: [main]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Salesforce CLI
run: npm install --global @salesforce/cli
- name: Log in with the JWT bearer flow
env:
SF_JWT_KEY: ${{ secrets.SF_JWT_KEY }}
run: |
echo "$SF_JWT_KEY" > server.key
sf org login jwt --client-id "${{ secrets.SF_CLIENT_ID }}" \
--jwt-key-file server.key --username "${{ secrets.SF_USERNAME }}" \
--instance-url https://login.salesforce.com --alias target
rm server.key
- name: Validate with local tests (no changes saved)
run: |
sf project deploy validate --source-dir force-app \
--test-level RunLocalTests --target-org target --wait 60
When the pull request is approved, release the validated components within 10 days with sf project deploy quick --job-id <validation job Id> --target-org target, which skips rerunning the tests. Production orgs should use a dedicated integration user with only the permissions the deployment needs.
b. Salesforce-Specific DevOps Platforms
These tools are designed specifically for Salesforce and provide higher-level abstractions and integrations with Salesforce metadata and processes.
- Salesforce DevOps Center: A managed-package solution for managing changes and releases. Salesforce recommends migrating projects to Lifecycle Center before support ends on June 4, 2027.
- Copado: A leading commercial DevOps platform built on Salesforce. Offers comprehensive features for release management, compliance, testing, and environment management.
- Gearset: A popular commercial DevOps solution known for ease of use, intelligent comparisons, and automated deployments.
- AutoRABIT: A comprehensive DevOps suite for Salesforce covering release management, continuous delivery, data loading, and more.
Choosing the right tool depends on your team's size, budget, existing technology stack, and specific Salesforce development needs.
5. Key CI/CD Practices for Salesforce
Implementing CI/CD successfully for Salesforce involves adopting several key practices that ensure code quality, reliability, and efficient delivery.
a. Version Control (Git)
- Central Repository: Store supported Salesforce metadata, including Apex, LWC, custom objects, profiles, and permission sets, in Git. Document and reconcile changes that cannot be retrieved or deployed through Metadata API.
- Branching Strategy: Adopt a clear branching strategy (e.g., Gitflow, GitHub Flow) to manage development, features, releases, and hotfixes.
- Single Source of Truth: Your Git repository should be the definitive source of truth for your Salesforce metadata.
b. Automated Testing
- Apex Unit Tests: Ensure all Apex classes and triggers have comprehensive unit tests. CI/CD pipelines should automatically run these tests.
- LWC Jest Tests: Implement Jest tests for your Lightning Web Components to validate client-side behavior.
- UI/End-to-End Tests: Consider tools like Selenium, Provar, or Cypress for automated UI testing of critical user flows.
c. Static Code Analysis
- Tools: Integrate tools like PMD Apex, Checkmarx, or SonarQube into your pipeline.
- Purpose: Automatically scan Apex code for common bugs, security vulnerabilities, and coding standards. Provides early feedback to developers.
d. Environment Management
- Dedicated Environments: Use dedicated sandboxes for development, integration, and UAT, and a separate production org.
- Scratch Orgs: Leverage Salesforce DX scratch orgs for isolated, short-lived development environments.
- Environment Sync: Regularly refresh sandboxes and ensure metadata consistency between environments.
e. Release Management & Approvals
- Automated Deployments: Automate the deployment process to various environments.
- Approval Gates: Implement manual approval steps for critical stages (e.g., deployment to production) to ensure human oversight.
- Recovery Strategy: Prepare and test a recovery plan, including corrective deployments and data restoration where applicable.
How do pipelines authenticate securely?
Use a dedicated integration identity and a supported headless authentication flow for each target org. For example, JWT authentication uses an approved client application and a certificate rather than an interactive login. Grant only the permissions needed for the pipeline's operations, and use separate identities or credentials where appropriate for different environments. Store private keys and other credentials in the CI platform's secret manager, restrict access, avoid printing them in logs, and rotate them according to policy. Verify that the org's authentication policies permit the chosen flow. See the Salesforce JWT authentication guidance.
6. Deployment Best Practices
Beyond CI/CD, several general best practices apply to all Salesforce deployments to ensure success and minimize risk.
- Plan Thoroughly: Define what needs to be deployed, the order of deployment, and the target environment.
- Communicate Changes: Inform all stakeholders about upcoming deployments and their impact.
- Backup Before Deployment: Always perform a full backup of your target environment before a major deployment.
- Validate First, Deploy Second: Always run a validation deployment to the target org before a full deployment.
- Deploy During Off-Peak Hours: Schedule production deployments during times of low user activity to minimize disruption.
- Test in Target Environment: Perform smoke tests and critical path testing in the target environment immediately after deployment.
- Handle Data vs. Metadata: Deployment tools handle metadata. Data migration tools (e.g., Data Loader, Salesforce CLI
datacommands) are needed for data. - Automate Where Possible: Reduce manual steps to minimize human error and increase speed.
- Monitor Post-Deployment: Keep an eye on system performance, error logs, and user feedback after a deployment.
- Document Deployments: Keep a record of what was deployed, when, by whom, and any issues encountered.
How do you handle destructive changes and recovery?
Plan deletions and their dependencies as part of the release, and prepare a recovery path before deploying. Salesforce supports destructive change manifests before or after a deployment, so order changes to satisfy dependencies and validate the complete release against the target org. Review the impact on data and downstream integrations, and back up what is needed before removal. A successful metadata deployment is not automatically reversible, and redeploying earlier metadata may not restore deleted data or every prior setting. Test corrective deployments and data restoration in a suitable environment, and use forward fixes when restoring the previous state is not feasible. See the destructive changes guidance.
7. Conclusion & Future Outlook
Salesforce deployment has evolved significantly, moving from manual processes to sophisticated CI/CD pipelines. Embracing these modern practices is no longer optional but a necessity for efficient, high-quality, and scalable Salesforce development.
Key Takeaways
- Automate Delivery Steps: Automate build, test, and delivery checks while retaining production approval when required.
- Version Control is Foundational: Git is the single source of truth for your Salesforce metadata.
- Test Early and Often: Automated testing (Apex, LWC, UI) is critical for catching issues before they reach production.
- Choose the Right Tools: Leverage SFDX CLI and suitable CI/CD platforms to build your pipeline.
- Prioritize Best Practices: Plan, validate, communicate, and monitor every deployment.
Salesforce delivery practices continue to evolve, including the transition from the DevOps Center managed package to Lifecycle Center. CI/CD skills and infrastructure help teams deliver changes more reliably and assess deployment outcomes.
Frequently asked questions
What is the difference between change sets and Salesforce CLI deployments?
Change sets move metadata between connected orgs through the Setup UI and keep no history. Salesforce CLI deploys from source files, so every change is tracked in Git, can be reviewed in a pull request and can be automated in a pipeline.
What code coverage does Salesforce require for production?
At least 75% of your Apex code must be covered by tests, all tests must pass, and every trigger must have some coverage. Aim higher and test real behaviour, not just lines.
What is a quick deploy?
Run sf project deploy validate with Apex tests against production. If it succeeds, you can release the same components within 10 days with sf project deploy quick and the job Id, without running the tests again. Note that sf project deploy start --dry-run does not produce a quick-deployable validation.
Is DevOps Center still supported?
Salesforce is ending support for the DevOps Center managed package on 4 June 2027 and recommends moving to Lifecycle Center, previously called Next-Generation DevOps Center. Lifecycle Center opens from the App Launcher with no package to install and keeps the Git-backed, work-item pipeline approach.
How do you authenticate Salesforce CLI in a CI pipeline?
Use the JWT bearer flow: create a connected app or external client app with a certificate, store the private key as a pipeline secret, and run sf org login jwt. Don't store user passwords in the pipeline.
Sources: Salesforce Help: DevOps Center managed package end of support · Salesforce CLI Command Reference · Deploying Apex