Skip to content

Steps to Set Up Visual Studio Code for Salesforce DX

Steps to Set Up Visual Studio Code (VS Code) for Salesforce DX Environment.

1. Sign up for Developer Org

Sign up for a developer sandbox here. Reset your password. You need both your username and password to authenticate your developer sandbox with the Salesforce CLI in a later step.

2. Install the Command Line Interface (CLI)

2.1 Install the CLI from Salesforce CLI.

Download Salesforce CLI

2.2 Confirm the CLI is properly installed and on the latest version by running the following command from the command line.
sf update

2.3 You should see output like  updating CLI

The Salesforce CLI is a powerful command line interface that simplifies development and build automation when working with your Salesforce org. Use it to:

  • Aggregate all the tools you need to develop with and perform commands against your Salesforce org
  • Synchronize source to and from scratch orgs
  • Create and manage orgs
  • Import and export data
  • Create and execute tests
  • Create and install packages

3. Install Visual Studio Code

Download and install the latest version of Visual Studio Code for your operating system.

Download Visual Studio Code

4. Install Salesforce Extension Pack for Visual Studio Code

4.1 Launch Visual Studio Code.

4.2 On the left toolbar, click the Extensions icon

4.3 Search for Salesforce Extension Pack and click Install.

Install Salesforce Extension Pack

Salesforce Extensions for Visual Studio Code depend on the Java Platform, Standard Edition Development Kit (JDK). It requires an installation of either JDK version 17 (Recommended), JDK version 11, or JDK version 8. 

By default, the extension attempts to locate your local Java installation by looking for a JAVA_HOME or JDK_HOME environment variable on your computer. If the extension can’t find your Java installation, or if you want it to use a different installation, change the salesforcedx-vscode-apex.java.home setting.

a) Select File > Preferences > Settings (Windows or Linux) or Code > Preferences > Settings (macOS).

b) Search for apex.

c) Change the salesforcedx-vscode-apex.java.home setting to the full pathname of your Java Runtime. Do not set it to the Java executable itself. Note that this pathname can’t point to a location inside your project folder. For example:

MacOS:

For Mac OS X 10.5 or later, run /usr/libexec/java_home in your Terminal to get the default JDK location. To find all installed JDKs, use /usr/libexec/java_home -V.

{
  "salesforcedx-vscode-apex.java.home": "/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home"
}

Windows:

{
  "salesforcedx-vscode-apex.java.home": "C:\\Program Files\\Eclipse Adoptium\\jdk-17.0.2.8-hotspot"
}

5. Create a Salesforce DX Project

5.1 In Visual Studio Code, open the Command Palette by pressing Ctrl+Shift+P (Windows) or Cmd+Shift+P (macOS).

5.2 Type SFDX: Create Project with Manifest

Create Project with Manifest

5.3 Select project type ‘default’

5.4 Provide project name. e.g. DYDCDemo

5.5 Select project folder. Click on Create Project button.

6. Authorize Your Developer Org

6.1 In Visual Studio Code, open the Command Palette by pressing Ctrl+Shift+P (Windows) or Cmd+Shift+P (macOS).

6.2 Type SFDX.

6.3 Select SFDX: Authorize an Org.

6.4 Press Enter to accept the Project Default login URL option.

6.5 Press Enter to accept the default alias. This opens the Salesforce login in a separate browser window.

6.6. Log in using your Trailhead Playground credentials.

6.7 If prompted to allow access, click Allow.

7. Create a Lightning Web Component

7.1 In Visual Studio Code, open the Command Palette by pressing Ctrl+Shift+P (Windows) or Cmd+Shift+P (macOS).

7.2 Type SFDX.

7.3 Select SFDX: Create Lightning Web Component.

7.4 Enter helloDYDC for the name of the new component.

7.5 Press Enter to accept the default force-app/main/default/lwc.

7.6 Press Enter.

7.7 View the newly created files in Visual Studio Code

Sample LWC

8. Deploy to Your Developer Org

8.1 Right-click the default folder under force-app/main

8.2 Click SFDX: Deploy Source to Org.

Deploy Source to Org

8.3 In the Output tab of the integrated terminal, view the results of your deployment. If the command ran successfully, a Deployed Source message lists the three files that were uploaded to the org.

Output Tab

Recommended Articles

Tags:

Share this article...

Please Leave a Comment

error: Content is protected !!

Discover more from DYDC

Subscribe now to keep reading and get access to the full archive.

Continue reading