Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
3D rendered Salesforce CLI icon representing command line access for admins.
Admin

Salesforce CLI for Admins: Boost Efficiency

The Salesforce CLI, paired with Visual Studio Code, gives you a direct line into your org. This guide covers the groundwork developers and admins need to automate the repetitive work and get the time back.

Key takeaways The Salesforce CLI and Visual Studio Code carry most of the day-to-day work in Salesforce development and administration. The sf command set is the modern, simplified syntax for Salesforce CLI operations. Authenticating orgs with sf org login web and managing metadata with sf project retrieve start are the fundamentals. Both tools cut manual effort and give administrators and developers back a meaningful amount of time.

The Salesforce Administrator role keeps changing, and picking up new tools pays for itself in productivity. This article covers the Salesforce CLI and Visual Studio Code for administrators and developers who have not used either.

Understanding Salesforce CLI

The Salesforce CLI (Command Line Interface) is a local command-line utility for working with your Salesforce orgs. You use it to create and manage Salesforce projects on your own machine, which you can then put under version control in a repository like GitHub or BitBucket. It is how your machine reaches Salesforce metadata and connects to orgs for deployments, retrievals, testing, and more.

The CLI lives in a terminal, which puts some people off. Visual Studio Code wraps it in an interface that is easier to get along with.

Visual Studio Code: the developer's editor

Visual Studio Code (VS Code) is a free, open-source source code editor from Microsoft that runs on every major platform. You get an integrated terminal and a file explorer in the same window.

VS Code welcome screen with terminal and file explorer

Installing Visual Studio Code

Download VS Code from the official website: https://code.visualstudio.com/. There are installers for Windows, macOS, and Linux.

Installing Salesforce CLI

Download the installer from the official Salesforce CLI documentation: https://developer.salesforce.com/tools/sfdxcli, then follow the instructions for your platform. Check the install by running sf --version in your terminal.

Installing Salesforce extensions for VS Code

VS Code needs extensions before it can do anything useful with Salesforce metadata. Install the Salesforce Extension Pack or Salesforce Extension Pack (Expanded) from the VS Code Marketplace:

  1. Open Visual Studio Code.
  2. Navigate to the Extensions view (Ctrl+Shift+X or ⌘+Shift+X).
  3. Search for "Salesforce Extension Pack".
  4. Click "Install" on the extension published by Salesforce.

Creating a Salesforce project

Keep all your Salesforce projects under one dedicated folder on your local machine.

  1. Create a root folder for your Salesforce projects (e.g., ~/SalesforceProjects).
  2. Open this folder in Visual Studio Code.
  3. Open the Command Palette (Ctrl+Shift+P or ⌘+Shift+P).
  4. Type sfdx and select SFDX: Create Project.
  5. Choose the Standard project template.

That generates the standard project structure in your VS Code workspace. Metadata files live in the force-app/main/default directory.

Salesforce CLI command evolution

The CLI has been through a few names: Force.com CLI, then SFDX, and now the consolidated sf CLI. The sf command set uses a simpler noun-verb syntax.

Older sfdx commands may still function, and new work should use the modern sf commands:

  • Legacy: sfdx force:source:deploy
  • Modern: sf project deploy start

Salesforce groups commands into sets, org for org management and project for project-specific operations.

Key Salesforce CLI commands

Authenticating a Salesforce org

Before the CLI can touch an org, you have to authenticate it, which usually means a web-based login flow:

sf org login web --alias <your_alias> --browser <browser_name> --instance-url <your_instance_url>
  • sf org login web: starts a web-based login in the org command set.
  • --alias <your_alias>: gives the org a nickname so you can refer to it easily.
  • --browser <browser_name>: picks the browser to authenticate in (e.g., chrome, firefox).
  • --instance-url <your_instance_url>: the login URL of your Salesforce org.

This opens your default browser on the Salesforce login page. Once you are authenticated, you can verify the connection.

Displaying connected orgs

To list the orgs you have authenticated:

sf org list

The output is a table with the org type, alias, username, Org ID, status, and expiration date where one applies.

Retrieving metadata

To pull metadata from an authenticated org into your local project:

sf project retrieve start --metadata <MetadataType>:<MetadataName> --target-org <your_alias>
  • sf project retrieve start: starts a metadata retrieval in the project command set.
  • --metadata <MetadataType>:<MetadataName>: the type and name of the metadata to retrieve (e.g., Flow:My_Flow).
  • --target-org <your_alias>: the alias of the org to retrieve from.

Originally reported by salesforceben.com

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment