LinuxCommandLibrary

sfdx

Develop, manage, and deploy Salesforce applications

TLDR

Authorize a Salesforce Organization

$ sfdx force:auth:web:login --setalias [organization] --instanceurl [organization_url]
copy


List all authorized organizations
$ sfdx force:org:list
copy


Open a specific organization in the default web browser
$ sfdx force:org:open --targetusername [organization]
copy


Display information about a specific organization
$ sfdx force:org:display --targetusername [organization]
copy


Push source metadata to an Organization
$ sfdx force:source:push --targetusername [organization]
copy


Pull source metadata from an Organization
$ sfdx force:source:pull --targetusername [organization]
copy


Generate a password for the organization's logged-in user
$ sfdx force:user:password:generate --targetusername [organization]
copy


Assign a permission set for the organization's logged-in user
$ sfdx force:user:permset:assign --permsetname [permission_set_name] --targetusername [organization]
copy

SYNOPSIS

The sfdx command functions as a gateway to numerous specialized Salesforce commands, typically following a TOPIC:COMMAND structure.

sfdx [GLOBAL_OPTIONS] TOPIC:COMMAND [COMMAND_OPTIONS] [ARGUMENTS]

Example: sfdx force:source:deploy --sourcepath force-app

Use sfdx --help or sfdx TOPIC:COMMAND --help to get specific command usage information.

PARAMETERS

--json
    Outputs results in a machine-readable JSON format for scripting and automation.

--loglevel <level>
    Sets the logging verbosity level for command output (e.g., info, debug, error).

--target-org <aliasOrUsername> / -o <aliasOrUsername>
    Specifies the Salesforce org (alias or username) to execute the command against. Often referred to as the default org.

--api-version <version>
    Overrides the default API version used for the command's operations.

--help / -h
    Displays detailed help information for the current command or topic.

--verbose
    Provides additional output for troubleshooting and detailed command execution information.

DESCRIPTION

sfdx (Salesforce DX CLI) is a powerful, open-source command-line interface developed by Salesforce. It empowers developers and administrators to manage Salesforce organizations, develop applications, and automate various tasks efficiently. sfdx serves as the primary tool for interacting with Salesforce, offering a comprehensive suite of commands for common development workflows. These include creating and managing scratch orgs, deploying and retrieving metadata, running Apex tests, managing data, and facilitating continuous integration/continuous delivery (CI/CD) pipelines. As an integral component of the Salesforce DX development model, it champions source-driven development, enhancing collaborative teamwork, and enabling robust automation. The CLI supports diverse authentication methods and seamlessly integrates with popular IDEs and version control systems, streamlining the entire Salesforce development lifecycle.

CAVEATS

  • sfdx requires Node.js and npm for installation and ongoing use. Compatibility issues with Node.js versions can sometimes arise.
  • Due to its extensive functionality, sfdx has a steep learning curve for new users, with hundreds of commands and subcommands.
  • Setting up various authentication methods (Web, JWT Bearer Flow, Device Flow) can be complex but is crucial for seamless operation.
  • The CLI is under active development, meaning commands and flags can evolve, sometimes leading to breaking changes between versions. Regular updates are recommended.
  • Many commands rely on the presence of an sfdx-project.json file in the current working directory to define the project structure and metadata paths.

<I>SOURCE-DRIVEN DEVELOPMENT</I>

sfdx fundamentally promotes a paradigm where your version control system (e.g., Git) serves as the single source of truth for all Salesforce metadata and code. This approach ensures consistency, facilitates team collaboration, and simplifies deployments compared to direct org modifications.

<I>SCRATCH ORGS</I>

A key innovation enabled by sfdx is the concept of scratch orgs. These are temporary, configurable, and disposable Salesforce orgs that can be quickly provisioned and deleted. They provide isolated development environments, perfect for feature development, bug fixes, automated testing, and CI/CD pipelines, without impacting shared development sandboxes.

<I>EXTENSIBILITY WITH PLUGINS</I>

The sfdx CLI is highly extensible through its plugin architecture. Developers can install official, community-contributed, or custom plugins to add new commands, integrate with external systems, or extend existing functionalities, tailoring the CLI to specific organizational needs and workflows.

HISTORY

The sfdx CLI was officially launched in 2017 as a cornerstone of the Salesforce DX (Developer Experience) initiative. This launch marked a pivotal shift in Salesforce development practices, moving away from traditional org-driven methods like change sets and desktop IDEs (e.g., Force.com IDE) towards a more modern, source-driven, and automated workflow. sfdx consolidated and expanded upon functionalities previously scattered across less integrated tools and effectively superseded the older, less maintained force-cli. Its introduction aimed to align Salesforce development with industry-standard practices, promoting version control, automated testing, and seamless integration with Continuous Integration/Continuous Delivery (CI/CD) pipelines, thereby enhancing developer productivity and collaboration.

SEE ALSO

git(1): Fundamental for source-driven development, used to version control Salesforce metadata., npm(1): Node Package Manager, the primary tool for installing and managing sfdx CLI and its plugins., bash(1) or zsh(1): Common shell environments where sfdx commands are executed and scripted., vscode: Popular code editor with robust Salesforce extensions, often used in conjunction with sfdx.

Copied to clipboard