Sub topic 5
Installing the Salesforce Extension Pack
This chapter assumes you have already installed VS Code, the Salesforce CLI (sf), and a Java JDK, as covered in the earlier chapters. You should be comfortable running commands in a terminal and opening the VS Code Extensions view. You do not need a Salesforce org yet. You will connect one in a later chapter.
What the Extension Pack is
The Salesforce Extension Pack is a bundle. It does not contain features of its own. When you install it, VS Code installs a set of separate extensions that work together. Removing the pack does not remove those extensions automatically, because each one is installed as its own item.
The pack typically includes these extensions:
| Extension | What it does |
|---|---|
| Salesforce CLI Integration (`salesforce.salesforcedx-vscode-core`) | Adds the `SFDX:` commands to the Command Palette. These commands call the `sf` CLI for project creation, org authorization, deploy, and retrieve. |
| Apex (`salesforce.salesforcedx-vscode-apex`) | Starts the Apex language server. It provides code completion, go to definition, outline, and diagnostics. |
| Apex Replay Debugger (`salesforce.salesforcedx-vscode-apex-replay-debugger`) | Replays a debug log in the VS Code debugger. |
| Apex Interactive Debugger (`salesforce.salesforcedx-vscode-apex-debugger`) | Live debugging. It requires an org that supports it and is not used in this tutorial. |
| Visualforce (`salesforce.salesforcedx-vscode-visualforce`) | Editing support for Visualforce pages. |
| Lightning Web Components (`salesforce.salesforcedx-vscode-lwc`) | Editing support for LWC. |
| Aura Components (`salesforce.salesforcedx-vscode-lightning`) | Editing support for Aura. |
| SOQL (`salesforce.salesforcedx-vscode-soql`) | Query editing and a query builder. |
| Salesforce Einstein and Agentforce tools | AI-related extensions. |
The exact membership changes between releases. Treat the table as a guide. The extension list on the pack's page in the Marketplace is the authority for your installed version.
For this tutorial you mainly use three of them: Salesforce CLI Integration, Apex, and Apex Replay Debugger.
Installing from the Extensions view
- Open VS Code.
- Open the Extensions view with the square icon in the Activity Bar, or press
Ctrl+Shift+X(Cmd+Shift+Xon macOS). - Type
Salesforce Extension Packin the search box. - Pick the result published by Salesforce. The publisher name appears under the extension name and has a verified badge.
- Select Install.
VS Code downloads the pack and each extension it lists. This usually takes under a minute on a normal connection.
Check the publisher
Several third-party extensions use similar names. Only install the one published by Salesforce. Extensions run with your user's permissions and can read files in your workspace, so the publisher check is worth doing.
Installing from the command line
VS Code has a command-line interface for extensions. This is useful for scripted setups and for teammates who need the same environment.
code --install-extension salesforce.salesforcedx-vscode
code --list-extensions --show-versions | grep salesforceThe first command installs the pack by its identifier. The second lists installed extensions with their versions, filtered to those with salesforce in the name. On Windows PowerShell, replace grep salesforce with Select-String salesforce.
If code is not found, the VS Code command is not on your PATH. On macOS, open the Command Palette and run Shell Command: Install 'code' command in PATH. On Windows and Linux, the installer normally does this, and a new terminal window is often enough to pick it up.
Verifying the install
A successful install shows three signs.
- The Extensions view lists the pack and its member extensions under Installed.
- The Command Palette (
Ctrl+Shift+PorCmd+Shift+P) shows commands starting withSFDX:when you typeSFDX. - After you open a Salesforce DX project, the Output panel has entries for the Apex language server. Choose Apex Language Server in the dropdown at the top right of the panel.
The third sign only appears once a project is open. Right after the first install, you will see only the first two. This is normal.
Many commands appear only inside a project
Many Salesforce commands are hidden or disabled when your workspace is not a Salesforce DX project. VS Code decides this by looking for an sfdx-project.json file at the root of the folder you opened. If you open a parent folder, or a subfolder, the extensions will not activate fully.
This leads to a common mistake. You install the pack, open a random folder, search for SFDX: Create Project, and then find that other commands are missing. The create commands should still be available, because they do not need an existing project. Commands such as deploy and retrieve will not appear until you open a folder with sfdx-project.json in it.
The next chapter covers project creation.
Activation and the first start
Extensions do not all start when VS Code starts. Each one declares activation events, which are conditions that make VS Code load it. The Apex extension activates when you open an Apex file or a workspace that contains sfdx-project.json.
On first activation the Apex extension launches the language server as a Java process. During that startup you may see a message in the status bar such as "Indexing Apex symbols" or a spinner. Wait for it to finish before judging whether code completion works. On a small project it takes seconds. On a large project, the first index can take several minutes. Later starts reuse a cache.
If the language server fails to start, the usual cause is a missing or wrong Java version. The previous chapter showed how to set salesforcedx-vscode-apex.java.home. The troubleshooting chapter returns to this.
Updates and versions
VS Code updates extensions automatically by default. For a development environment this is usually what you want, but there are two cases where you might not.
- A new release changes behavior in the middle of a task you need to finish.
- You need to match a version used by your team or by a build image.
You can turn off automatic updates for a single extension. Open the extension in the Extensions view, open the gear menu, and clear Auto Update. You can also install a specific older version from the same gear menu with Install Specific Version....
The Salesforce extensions release on a regular schedule, often weekly. Release notes are linked from each extension's page. If something stops working after an update, the release notes are the first place to look.
Compatibility with the CLI and Java
The extensions call the sf CLI and require a supported Java version for the language server. A new extension release can raise the minimum Java version. When that happens, the symptom is that the Apex features stop working after an update, even though you changed nothing. Check the Apex Language Server output channel first. It states the reason when it fails to start.
Workspace recommendations
Teams can pin the extension set for everyone by committing a file named .vscode/extensions.json to the project:
{
"recommendations": [
"salesforce.salesforcedx-vscode"
]
}When someone opens the project, VS Code offers to install the recommended extensions. This does not install anything without the user accepting. A project generated by sf project generate includes such a file with the Salesforce recommendations already, so you may find it in the project you create in the next chapter.
Restricted environments
Some corporate networks block the Visual Studio Marketplace or require a proxy. Symptoms include an endless loading spinner in the Extensions view or an error that the gallery cannot be reached. You have two options.
- Configure the proxy in VS Code with the
http.proxysetting, or set theHTTPS_PROXYenvironment variable before starting VS Code. - Download the
.vsixfiles from the Marketplace on a machine with access, copy them over, and install each one:
code --install-extension ./salesforcedx-vscode-core.vsixA .vsix file installs one extension. The pack is only a list, so you must install each member extension you need. Offline installs also need dependencies installed first. If an install fails, the error names the missing extension.
Disabling and uninstalling
You can disable a single member extension without removing the pack. Open it in the Extensions view and choose Disable or Disable (Workspace). Workspace-only disabling is useful, for example, when you want to turn off the Lightning extensions in a project that has only Apex.
To remove everything, uninstall the pack and then each member extension. Uninstalling only the pack leaves the members in place.
Common errors
| Symptom | Likely cause | What to do |
|---|---|---|
| No `SFDX:` commands in the Command Palette | Pack not installed, or install did not finish | Check the Installed list, then reload the window with **Developer: Reload Window** |
| Commands appear but deploy and retrieve are missing | Folder opened is not the project root | Open the folder that directly contains `sfdx-project.json` |
| Apex files have no completion or syntax errors | Language server not running | Open the Apex Language Server output channel and read the error |
| `code` not found in the terminal | VS Code not on PATH | Install the shell command, or open a new terminal |
| Extensions stuck installing | Network, proxy, or Marketplace blocked | Configure the proxy, or install `.vsix` files |
Exercises
Exercise
You install the Salesforce Extension Pack and open a folder. The Command Palette shows SFDX: Create Project, but not the deploy commands. What is the most likely reason, and how do you fix it?
Show answer
The folder you opened is not a Salesforce DX project root, so there is no sfdx-project.json at its top level. The create commands do not need a project, but deploy and retrieve do. Open the folder that directly contains sfdx-project.json (File > Open Folder), or create a project first.
Exercise
A teammate says they uninstalled the Salesforce Extension Pack, but Apex code completion still works in their VS Code. Why?
Show answer
The pack is only a bundle. Each member extension, including the Apex extension, is installed separately, so uninstalling the pack does not remove them. They must uninstall or disable each member extension.
Exercise
Write the command that installs the pack from a terminal, and a command that confirms it is installed.
Show answer
code --install-extension salesforce.salesforcedx-vscode installs it. code --list-extensions --show-versions lists installed extensions with versions, and you can filter the output for salesforce.