Sub topic 1
What the Salesforce CLI Does
The Salesforce CLI is a command-line tool for managing Salesforce development work. It lets you connect to orgs, create projects, deploy metadata, retrieve metadata, query records, and run Apex without opening every tool in a browser.
This chapter assumes basic terminal skills, familiarity with Salesforce orgs and metadata, and Node.js if you install the CLI with npm.
Prerequisites
You need:
- A terminal
- A Salesforce org you can authorize
- Node.js and npm for the installation method shown here
- Basic knowledge of Salesforce metadata and Apex
Install the CLI and Check the Version
Install the Salesforce CLI globally with npm:
npm install --global @salesforce/cli
sf --versionThe second command prints the installed version. If your shell cannot find sf, check that npm's global bin directory is on your PATH. The PATH is the list of directories your shell searches for executable commands.
The CLI can manage several Salesforce environments, called orgs. Later commands use aliases and default settings to decide which org to target.
How `sf` Commands Are Structured
An sf command usually has this structure:
sf <topic> <command> [flags]A topic groups related operations. A command performs one operation. A flag changes that operation.
For example:
sf org list
sf org display --target-org myorg
sf data query --query "SELECT Id, Name FROM Account LIMIT 5"Here, org and data are topics. list, display, and query are commands. Options such as --target-org and --query are flags.
Commands often use nouns for topics and verbs for actions. This structure makes related commands easier to discover.
Finding Help for Commands and Flags
Use help when you need the exact syntax or available flags:
sf help
sf org --help
sf org login web --help
sf data query --helpStart with sf help to browse the command tree. Use --help on a specific command to inspect its arguments, flags, examples, and required values.
Exercise
In sf data query --query "SELECT Id FROM Account" --json, identify the topic, command, and flags.
Show answer
data is the topic, query is the command, and --query and --json are flags.