Skip to main content

Set Up VS Code, Salesforce CLI and Java for Development

Updated Add a comment
In plain words: Visual Studio Code (VS Code) is the code editor most Salesforce developers use. Add Java, the Salesforce CLI, and the Salesforce Extension Pack, and your computer becomes a full Salesforce development setup. You can write Apex, build Lightning Web Components (LWC), and deploy metadata from your own machine instead of the in-browser Developer Console. The whole setup takes about 15 minutes.

Modern Salesforce development is "source-driven." You write and test code on your local computer, keep it in Git, and then deploy it to a scratch org, sandbox, or Developer Edition org. VS Code gives you a large library of extensions, good syntax highlighting, and built-in Git support.

This guide walks through each step, in order, to get your machine ready for Salesforce DX (SFDX) development.

Key Points Summary

  • The Developer Console can't build Lightning Web Components. For real development, you need a local editor.
  • Salesforce's official extensions are built for VS Code, so it's the editor Salesforce supports and updates first.
  • The modern Salesforce CLI command is sf. The older sfdx style is legacy.
  • You need a Java JDK (version 21 is recommended; 17 and 11 also work) because Apex features in VS Code run on Java.
  • Use SFDX: Create Project with Manifest for sandboxes and Developer Edition orgs, and SFDX: Create Project for scratch orgs.

What You Need

You'll install four tools, in this order:

  • Java JDK (21 recommended): Powers Apex code completion and error checking in VS Code.
  • Salesforce CLI: Lets your computer talk to your Salesforce orgs.
  • Visual Studio Code: The editor where you write code.
  • Salesforce Extension Pack: Teaches VS Code about Apex, LWC, SOQL, and more.

Step 1: Install and Configure Java (JDK 21)

The Salesforce Extension Pack uses a background tool called the Apex Language Server. It gives you code completion, syntax checking, and inline error highlighting for Apex. It runs on Java, so you need the Java Development Kit (JDK).

  • Download the JDK: Salesforce supports JDK 11, 17, or 21, and recommends JDK 21. Download it from the Oracle website or use a free open-source build like Eclipse Temurin from Adoptium. Even if you already have a different Java version, you still need one of these three.
  • Point VS Code to Java (all systems): After you install VS Code in Step 3, open Settings, search for salesforcedx-vscode-apex.java.home, and enter your JDK folder path. This is the most reliable option, especially if you have more than one Java version.
  • Set the Environment Variable (Windows, optional):
    1. Right-click the Start menu, select System, then click Advanced system settings.
    2. Click Environment Variables at the bottom.
    3. Under System variables, click New... and name the variable JAVA_HOME.
    4. Paste your JDK folder path (for example, C:\Program Files\Java\jdk-21) into the value field and click OK.
    5. Edit the Path variable and add %JAVA_HOME%\bin.
How to Verify Your Java Setup:
Open a new Command Prompt (Windows) or Terminal (Mac), type java --version, and press Enter. If Java is set up correctly, you'll see the installed version number.
Trap: "'java' is not recognized" Error
If your terminal says 'java' is not recognized as an internal or external command, Windows doesn't know where Java is installed. Check your JAVA_HOME path, make sure %JAVA_HOME%\bin is in your Path variable, and open a new terminal window. Old windows don't pick up the change.

Step 2: Install the Salesforce CLI

The Salesforce Command Line Interface (CLI) is the bridge between your computer and your Salesforce orgs. It logs you in to orgs, retrieves metadata, deploys code, and runs tests. The VS Code extensions use it behind the scenes, so you need it even if you never type a CLI command yourself.

  • Download the installer from the official Salesforce CLI page.
  • Run the installer and accept the default options.
  • Open your terminal and type sf --version to confirm it worked.
  • Keep it current by running sf update from time to time.

Step 3: Install Visual Studio Code

VS Code is Microsoft's free, lightweight code editor. It runs on Windows, Mac, and Linux.

  • Download the right version for your system from code.visualstudio.com.
  • Run the installer and follow the steps. If you already have VS Code, update it. The Salesforce Extension Pack needs version 1.90 or later.

Step 4: Install the Salesforce Extension Pack

Out of the box, VS Code doesn't know what Apex or LWC is. The official Salesforce Extension Pack adds that knowledge.

  1. Open VS Code.
  2. Click the Extensions icon in the left sidebar (or press Ctrl+Shift+X on Windows / Cmd+Shift+X on Mac).
  3. Search for Salesforce Extension Pack.
  4. Click Install on the official pack from Salesforce.

Note: This one pack installs several extensions for you, including Apex language support, the Apex Replay Debugger, LWC support, the SOQL Builder, and Visualforce tools.

Step 5: Create a Salesforce DX Project

You can't just open an empty folder and start coding. Salesforce needs a specific folder structure, called an SFDX project, to know where classes, components, and config files go. Many features won't work unless the folder you open has an sfdx-project.json file.

Procedure: Creating Your First Project
1. Open the Command Palette with Ctrl+Shift+P (Windows) or Cmd+Shift+P (Mac).
2. Pick the right command:
   • SFDX: Create Project with Manifest for sandboxes and Developer Edition orgs (most common).
   • SFDX: Create Project for scratch org development.
3. Select the Standard project template.
4. Name your project (for example, MyFirstSalesforceApp).
5. Choose a folder on your computer to save it in.

Step 6: Authorize Your Salesforce Org

Your project now exists on your computer. Next, connect it to your Salesforce org (sandbox, Developer Edition, or production).

  1. Open the Command Palette (Ctrl+Shift+P).
  2. Type and select SFDX: Authorize an Org.
  3. Choose your login URL: Production for production and Developer Edition orgs, Sandbox for sandboxes, or Custom to enter your org's My Domain URL.
  4. Enter an alias for the org (for example, DevSandbox) so it's easy to pick later.
  5. Your browser opens. Log in with your Salesforce username and password, then click Allow when asked to grant access.
Developer Trap: Wrong Login URL
A very common beginner mistake is trying to log in to a sandbox with the login URL set to login.salesforce.com. Sandboxes use test.salesforce.com, or your sandbox's My Domain URL. If login keeps failing, check your login URL choice first.

Step 7: Work with SFDX Commands

With your org connected, you're ready to write and deploy code. There are two main ways to work with Salesforce from VS Code:

  • Menus and the Command Palette: Right-click any file or folder in the sidebar and select "SFDX: Deploy This Source to Org" to push your changes, or "SFDX: Retrieve This Source from Org" to pull the latest version down. The Command Palette (Ctrl+Shift+P) lists every SFDX command.
  • The Integrated Terminal: For more control, open the VS Code terminal (Ctrl+`) and type sf commands directly, like the ones below.
# Log in to a sandbox and give it an alias
sf org login web --alias DevSandbox --instance-url https://test.salesforce.com

# Deploy everything in your force-app folder
sf project deploy start --source-dir force-app

# Retrieve the metadata listed in your manifest
sf project retrieve start --manifest manifest/package.xml

Step 8: Add a Few Helpful Extras

The official pack is all you need to start. These extras make daily work easier:

  • Org Browser (built in): Comes with the Extension Pack. It lets you browse the metadata in your org (objects, classes, layouts, and more) and retrieve it into your project with a click.
  • Prettier - Code Formatter: Formats your HTML, CSS, and JavaScript automatically, so your code always looks clean and consistent. New SFDX projects already include a Prettier config file.
  • Salesforce Package.xml Generator: A community extension that gives you a visual way to pick metadata and build a package.xml file. Handy when you work with sandboxes instead of scratch orgs.

Frequently Asked Questions (FAQ)

Q: Do I really need to use VS Code? Can I use IntelliJ or Eclipse?

A: Third-party plugins exist for other editors, like Illuminated Cloud for IntelliJ. But Salesforce builds and updates its official extensions for VS Code, so that's where you get the newest LWC tools and CLI features first. Salesforce also publishes the extensions on the Open VSX Registry, so other VS Code-based editors can use them too.

Q: Can I just use the Developer Console in my browser?

A: The Developer Console is fine for a quick SOQL query or a short Anonymous Apex script. But it can't build Lightning Web Components, and it has no Git integration or modern code checks.

Q: What's the difference between sf and sfdx?

A: sfdx was the original Salesforce CLI command style. Salesforce rebuilt the CLI around the sf command, with a clearer structure (for example, sf project deploy start). Most old sfdx commands still work for now, but new docs and features use sf, so learn that style.

Q: Do I need to install Node.js?

A: Not for the basic setup. The Salesforce CLI installer includes what it needs. You'll need Node.js later if you run LWC Jest unit tests or use npm-based tools like Prettier from the command line.

360 Card: Your Salesforce Development Toolkit
  • Java (JDK 21 recommended): Runs the Apex Language Server behind the scenes for code completion and error checking.
  • Salesforce CLI (sf): The terminal tool that moves code and metadata between your computer and your orgs.
  • VS Code: The editor where you write your code.
  • Extension Pack: Connects VS Code to the CLI and gives you menus for deploying, retrieving, and debugging.
  • Setup order: Java ➔ CLI ➔ VS Code ➔ Extension Pack ➔ Create Project ➔ Authorize an Org.
Core Takeaway: Learning VS Code and the Salesforce CLI is the biggest productivity boost you can give yourself as a Salesforce developer. Once your setup is ready, press Ctrl+Shift+P (or Cmd+Shift+P) and create your first project.

Conclusion

Setting up VS Code changes how you build on Salesforce. By moving from the browser to local SFDX development, you get better code checking, debugging tools, and version control. Follow these steps, get comfortable with the Command Palette, and you'll be building and deploying Lightning Web Components in no time.

Happy coding!

Was this article helpful?

Have a question or spotted a mistake? Ask here about this article

Found this guide useful? Buy me a coffee (opens in a new tab)

Comments

Questions, corrections and your own experience are all welcome.