Sub topic 1
How VS Code, the Salesforce CLI, Java, and the extensions fit together
Prerequisites
This chapter assumes you have:
- Basic familiarity with Visual Studio Code (VS Code), such as opening folders and using the Command Palette.
- Comfort running commands in a terminal.
- A Salesforce org you may use for development, such as a Developer Edition org or a sandbox.
- A basic understanding of what Apex is. Apex is Salesforce's Java-like programming language for server-side logic.
You don't install anything in this chapter. It explains how the pieces relate, so the later installation steps make sense and failures are easier to diagnose.
The four parts
A working Apex setup in VS Code has four parts. Each does a different job.
| Part | Role | What breaks without it |
|---|---|---|
| VS Code | The editor and the host for extensions | Nothing else has a user interface |
| Salesforce CLI (`sf`) | Talks to your org: login, deploy, retrieve, run tests | Org commands fail or are missing |
| Java JDK | Runs the Apex language server | No code completion, navigation, or diagnostics for Apex |
| Salesforce Extension Pack | A bundle of VS Code extensions that connect the other parts | Commands such as `SFDX: Create Project` do not exist |
The extension pack does not replace the CLI or Java. It uses them. You install the CLI and the JDK on your machine, and the extensions find them.
How a request flows
Two different paths run through the tooling. Knowing which one a feature uses tells you which part to check when it fails.
The first path is editing. When you open an Apex file, the Apex extension starts a language server, which is a separate program that analyzes your code. It runs on Java. VS Code asks it for completions, definitions, and error markers. This path never contacts your org.
The second path is org actions. When you run a command such as SFDX: Deploy This Source to Org, the extension builds a Salesforce CLI command and runs it. The CLI uses the credentials it saved for your default org and sends the request to Salesforce.
Both paths share one more thing: the Salesforce DX project. This is a folder with an sfdx-project.json file at its root. The language server uses it to know where your source lives. The CLI uses it to know what to deploy. A later chapter covers creating one.
Why the split matters
Because the tools are separate, they fail separately. Compare these two symptoms:
- Code completion is missing, but
sf org listworks. The CLI is fine. Suspect Java or the language server. - Completion works, but a deploy command fails. The editor side is fine. Suspect the CLI, the org login, or the default org.
You can check the machine-level tools without opening VS Code:
code --version
sf --version
java -versionIf any of these prints "command not found", that tool is missing or not on your PATH. The PATH is the list of folders your terminal searches for programs. VS Code only sees the PATH it was started with, so after installing a tool you often need to restart VS Code.
Common errors at this stage
- Installing only the extensions. The extension pack installs quickly, so people stop there. The commands then appear in the Command Palette but fail, because the CLI is absent.
- Java installed but not found. The extension looks for a JDK in standard places. If yours lives elsewhere, the language server does not start. A setting named
salesforcedx-vscode-apex.java.homecan point it to the right folder. A later chapter covers this. - A JRE instead of a JDK. The Apex language server needs a full JDK. Check the extension documentation for the supported Java versions.
- No default org. Deploy and test commands need a target. Without a default org, they stop or ask you to choose one.
The order of installation
The concept dependencies give the order for the next chapters. Install VS Code, the CLI, and the JDK first, since they don't depend on each other. Then install the extension pack, which relies on all three. Then create a DX project and authorize an org. Only after that do deploy, test, and debug features work.
Exercise
Code completion for Apex does not appear in VS Code, but sf org list shows your org correctly. Which part of the setup should you check first, and why?
Show answer
Check Java. The Apex language server provides completion and runs on a Java JDK, so a missing or unfound JDK stops it. The CLI is not involved in editing, and sf org list working shows it is fine.