Rocket ship badge DevOps Launchpad

Rob Cowell · 19th October 2023

What is Salesforce DX? A deep dive into Salesforce’s developer toolset

Salesforce DX is a powerful set of developer tools, APIs and features aimed at streamlining the development lifecycle for building apps on the Salesforce platform. With Salesforce DX, it becomes much easier for Salesforce teams to adopt DevOps. DevOps makes it easier to manage code, gives greater confidence that your changes will work when deployed, and helps you get apps to market faster using industry-standard models.

What is Salesforce DX?

Salesforce DX provides Salesforce developers with a set of command-line tools and services to manage source code, sync it securely to scratch orgs for testing, and package it for deployment to production Salesforce orgs. There are many key DX features and capabilities we’ll explore in this post, including the Salesforce CLI, scratch orgs, second-generation packaging, version control integration, Visual Studio Code extensions and more.

Salesforce CLI and SF commands

The Salesforce CLI (command line interface) provides the ability to execute SF commands for working with Salesforce DX. The CLI is installed on your local machine and lets you manage orgs and source code without the need for a GUI (graphical user interface).

Some popular SF commands include:

  • sf push Push source code to a Salesforce org
  • sf pull Pull source code from a Salesforce org
  • sf org create Create a scratch org
  • sf status View push status

The CLI has commands for authorizing orgs, retrieving and deploying metadata, running tests and more. It’s a key tool that enables many Salesforce DX workflows.

Scratch orgs

Scratch orgs provide dedicated, short-lived Salesforce org environments to develop against that mirror your production org. The scratch org creates a replica of your schema, data model, and configured settings. This allows you to test changes in an org that looks just like prod without affecting your real data or users, which is a much safer way of working than pushing changes straight into prod and hoping for the best.

After making your code changes locally, you can instantly spin up a scratch org and push those changes to test how they would operate in a matching live environment. Any changes made within a scratch org aren’t saved back to your local source code. This gives you the flexibility to experiment risk-free while keeping your local source pristine.

Scratch orgs are fundamental to modern Salesforce development methods. They enable automated testing, experimentation, and developing against orgs that mirror your live environment.

Dev Hub org

A Dev Hub org stores the project metadata and namespaces that you want to make available across orgs. To use scratch orgs and packaging features, you first connect your CLI to your Dev Hub.

The Dev Hub allows you to seamlessly push and pull metadata between your local Git repository and connected orgs. This enables you to move code changes to scratch orgs for testing as well as to retrieve updated metadata from those orgs.

Second-generation packaging and unlocked packages

Unlocked packages allow easier management and distribution of code between Salesforce orgs. Similar to managed packages, second-generation packaging (2GP) allows the creation of self-contained sets of metadata and functionality to share as an app or component.

Key benefits of 2GP include being able to update package content after release, having multiple versions available in an org, and managing dependencies on other packages. Unlocked packages also help organize code for change management and make sharing your apps between orgs simple.

Version control integration

Salesforce DX is built to leverage your existing version control system for easy tracking of changes over time. Salesforce teams almost universally use Git, enabling source control best practices like branching. Version control ensures developers can work collaboratively on projects without the risk of overwriting changes.

By connecting your version control system to tools like the Salesforce CLI, you can sync source code changes bi-directionally between your local repository and Salesforce orgs. This is essential to enabling a true source-driven development process. Bringing version control to your process delivers so many benefits: increased visibility of changes going through your development pipeline, the ability to do peer review of changes, automation of testing and deployments, and much more.

Visual Studio Code extension

An extension for Visual Studio Code (VS Code) provides built-in tools for managing scratch orgs and source code directly within the editor, enabling a true integrated development environment for Salesforce.

The extension allows commands like creating scratch orgs and syncing source code seamlessly within VS Code. It also provides code highlighting, linting, and other features which can be tailored for your DX project.

SFDX metadata format

The SFDX metadata format defines how source code is structured and makes it easy to move code between Salesforce orgs. Metadata components like Apex classes, Lightning apps, and custom objects are packaged together into logical folders and files.

This standardized structure allows for seamless portability of code between orgs. The consistent format also facilitates working with source control and automating deployments across environments.

Dependency API

The Dependency API allows users to easily manage dependencies between packages and orgs. You can view the installation status of managed and second-generation packages, their relationships to other packages, and the chain of package ancestry.

Understanding package dependencies helps manage intricate installations across development, testing, and production orgs while preventing conflicts between package versions.

How is Salesforce DX different from Salesforce DevOps Center?

Salesforce DevOps Center provides a graphical user interface for working with scratch orgs and connecting to source control systems like GitHub on top of the Salesforce DX tools and processes.

Salesforce DX provides the underlying command line interface and services that enable DevOps Center and other tools. You can use the CLI and Salesforce DX capabilities directly without DevOps Center if desired for a more customizable DevOps process.

While DevOps Center offers an excellent graphical environment, the Salesforce CLI can be more flexible for integration with existing CI/CD pipelines and using DX functionality where you need it.

Can you use scratch orgs with sandboxes?

Yes, scratch orgs complement your existing sandboxes nicely. Scratch orgs are great for short-term development and automated testing needs. Sandboxes are better suited for ongoing integration testing, user acceptance testing, and staging environments.

Scratch orgs provide completely separate environments that mirror your production orgs. This makes them well-suited for fast iterations of development changes. They allow you to test new functionality without risking other work streams that may be using your sandboxes.

Sandboxes persist over longer periods and allow you to set up and test more complex scenarios involving data integrations, user feedback, training etc. Sandboxes are your longer-lived environments for pre-production testing, while scratch orgs meet ephemeral development and automation needs.

Is Salesforce DX free?

Yes! Salesforce DX is completely free, allowing teams of all sizes to leverage the benefits of Salesforce DX at no added cost beyond your existing Salesforce licenses. The CLI-based model also means there’s no added burden on your internal IT infrastructure.

Why you should use Salesforce DX

Salesforce DX provides major benefits across the development process. Working locally using known tools like Visual Studio Code allows productivity gains by making the most of existing expertise. Developing against scratch orgs that match your production environment ensures that code will behave as expected when deployed.

Package management features make organizing and distributing code changes simple. Tight integration with version control systems like Git enables true source-driven development and collaboration.

Automated testing in disposable scratch orgs allows safe validation of changes. The entire toolchain aims to increase the confidence that changes will work as expected in production. Salesforce DX enables highly efficient DevOps workflows. Typical principles include using scratch orgs for local development, managing all changes in source control, creating packages for change sets, and automating deployments across environments.

This allows for continuous integration — where developers frequently merge code changes back to a shared main branch. Automated builds kick off tests in scratch orgs to surface issues early. Continuous delivery pipelines then push validated changes to downstream environments automatically. Combining these two techniques into a CI/CD pipeline becomes much easier with the adoption of Salesforce DX.

With DX, teams can achieve continuous integration, delivery, and deployment. Changes are tested and validated in lower environments before being deployed to production more easily, reducing risk and the need for manual processes.

Salesforce DX provides a flexible toolkit tailored for streamlining development on the Salesforce platform. Using industry standard workflows and tool integrations, Salesforce DX enables developers to deliver higher-quality applications faster.

Learn more about Salesforce DX

If you’d like to delve deeper, check out our Salesforce DX training course here on DevOps Launchpad, and earn a certificate to show off your skills!