Skip to main content

How to Set Up Visual Studio Code for Salesforce Development (SFDX Guide)

In plain words: Visual Studio Code (VS Code) is the industry-standard code editor for Salesforce developers. By pairing it with the Salesforce Extension Pack and the Salesforce CLI, you can write Apex, build Lightning Web Components (LWC), and deploy metadata right from your local computer, replacing the clunky, cloud-based Developer Console.

If you are serious about Salesforce development, moving away from the in-browser Developer Console to a local development environment is a must. Visual Studio Code (VS Code) offers a massive ecosystem of plugins, powerful syntax highlighting, and seamless Git version control integration.

In this guide, we will walk through the exact steps to configure VS Code for modern Salesforce DX (SFDX) development so you can start writing code efficiently.

Prerequisites

Before touching any code, you need two fundamental tools installed on your computer:

  • Salesforce CLI: This is the command-line interface that allows your computer to talk to your Salesforce org. Download the latest installer from the official Salesforce developer website. (Note: Salesforce is actively transitioning from the older sfdx commands to the newer, faster sf commands).
  • Visual Studio Code: Download and install the latest stable build of VS Code for your operating system (Windows, Mac, or Linux).

Step 1: Install the Salesforce Extension Pack

Out of the box, VS Code doesn't know what Apex or LWC is. We need to teach it by installing Salesforce's official extensions.

  1. Open VS Code.
  2. Click on the Extensions icon in the left sidebar (or press Ctrl+Shift+X on Windows / Cmd+Shift+X on Mac).
  3. Type Salesforce Extension Pack into the search bar.
  4. Click Install on the official pack provided by Salesforce.

Note: This single pack automatically installs everything you need, including Apex syntax highlighters, LWC support, SOQL builders, and Visualforce tools.

Step 2: Create a Salesforce DX Project

You cannot just open an empty folder and start coding. Salesforce requires a specific folder structure (an SFDX Project) to know where to place classes, components, and configuration files.

Procedure: Creating Your First Project
1. Open the VS Code Command Palette by pressing Ctrl+Shift+P (Windows) or Cmd+Shift+P (Mac).
2. Type SFDX: Create Project and hit Enter.
3. Select the Standard project template.
4. Give your project a name (e.g., MyFirstSalesforceApp).
5. Choose a folder on your computer to save the project.

Step 3: Authenticate with Your Salesforce Org

Now that your project is set up locally, you need to connect it to your target Salesforce environment (Sandbox, Developer Edition, or Production).

  1. Open the Command Palette (Ctrl+Shift+P).
  2. Type and select SFDX: Authorize an Org.
  3. Select your login URL (choose Production for standard Developer Edition orgs, or Sandbox for testing environments).
  4. Enter an alias for this org (e.g., DevSandbox) so you can remember it later.
  5. Your default web browser will open. Log in with your Salesforce credentials and click Allow when prompted for CLI access.
Developer Trap: Wrong Login URL
A very common mistake for beginners is trying to authorize a Sandbox while leaving the login URL set to login.salesforce.com. Sandboxes must always be routed through test.salesforce.com. If your authentication keeps failing, double-check your environment selection!

Step 4: Working with SFDX Commands

With your org connected, you are ready to write and deploy code. You have two main ways to interact with Salesforce from VS Code:

  • The Command Palette: Use Ctrl+Shift+P for point-and-click commands. For example, you can right-click any Apex class in your sidebar and select "SFDX: Deploy Source to Org" to push your changes to the cloud.
  • The Integrated Terminal: For faster, more advanced control, open the VS Code terminal (Ctrl+`) and type modern sf CLI commands directly. For instance, sf project deploy start deploys your entire project at once.

Step 5: Enhance Development with Extra Extensions

While the official Salesforce pack is mandatory, seasoned developers install a few extra community plugins to make life easier:

  • Prettier - Code Formatter: Automatically formats your HTML, CSS, and JavaScript so your code always looks clean and uniform.
  • Salesforce Package.xml Generator: A lifesaver for non-scratch org development. It provides a visual UI to select which metadata (like custom objects, fields, and layouts) you want to pull down from your org into VS Code.
360 Card: The SFDX Setup Checklist
1. Install the Salesforce CLI (sf command line).
2. Install Visual Studio Code.
3. Add the "Salesforce Extension Pack" via the VS Code Marketplace.
4. Run SFDX: Create Project to scaffold your folders.
5. Run SFDX: Authorize an Org to connect to the cloud.
Core Takeaway: Mastering VS Code and the Salesforce CLI is the single biggest productivity boost you can give yourself as a Salesforce Developer.

Conclusion

Setting up Visual Studio Code for Salesforce development transforms the way you write code. By migrating away from the browser and embracing local SFDX development, you gain access to powerful debugging tools, syntax checking, and version control. Follow these steps, explore the Command Palette, and you will be deploying enterprise-grade Lightning Web Components in no time.

Happy coding!