Skip to main content

August 5, 2020

Develop For Salesforce Using VSCode

The Most Popular IDE Out there

So you want to be a Salesforce developer, huh? Awesome! Development in Salesforce is currently supported in two ways—inside of the Org in the developer console, or in the open source integrated development environment (IDE) using Visual Studio Code (VSCode). 

Because VSCode is one of the most popular IDEs out there, most seasoned Salesforce developers primarily use VSCode for their projects because of the ease of use and custom functionality that is just not available in the Developer Console. Some of the advantages of VSCode include local development, third-party extensions, environment customization, and the ability to use source control, such as git. The initial setup for VSCode can be a bit daunting for new developers, so we decided to break down the steps.


Install the CLI

The first step is to download the Salesforce Command Line Interface (CLI) here. This allows you to perform Salesforce commands in VSCode or manually via your command line. Once the download is complete, follow the steps in the installer.

Install VSCode

Download and install the current version of VSCode here.

Install JDK 11

Download and install one of the three JDK options listed here. While any of the three will work for VSCode, I would recommend using the Zulu Java, because it is the only supported Java for Salesforce Data Loader; plus, why would you want to install this twice?

Open VSCode and Install Salesforce Extension Pack

Alright! Now that we have installed everything outside of VSCode, it’s time to install the Salesforce Extension Pack. When you open VSCode in the left panel, there will be several buttons. Click on the button fourth down that looks like a Tetris block (see Image below).

Click on it. In the new panel that appears, search for the Salesforce Extension Pack. Click on it and select install to begin the package installation.

Now that everything is installed, in order to make sure these different installations are working together correctly, go ahead and restart your computer (yes, it’s actually necessary). Once you have restarted your computer go ahead and open up VSCode.

Important Settings to Activate

On the bottom, left click on the gear button. Then Click on Settings. Under the User Settings, click on the extensions folder. Then Click on the first Salesforce Setting. Here we’ll find all of our customization settings. Some important settings to enable are Push-or-deploy-on-save and Retrieve-test-code-coverage enabled. Another setting to be aware of is the Java Home Path. If VSCode warns you that you don’t have Java installed and you’ve restarted your computer already, the Java Home setting is where you can specify the path to the Java library (requires a restart for it to take effect). For info on this, please see this help article.

Walkthrough of Initial Connection with Org

Alright! Now that everything is installed, let’s connect VSCode to the Org in which we are developing. Remember you cannot make changes to code in production Orgs, and it’s a best practice not to do your development in a production environment. The first step in using VSCode with Salesforce is to create a new Salesforce Project. Using CMD + Shift + P (CTRL + Shift + P Windows) enter SFDX: Create Project with Manifest and hit enter. Select the Standard project.

You will then be prompted to name your project. I recommend you name the project after the Org in which you’re planning to work. In this case, I’ll use VSCodeExample. Select where you want to create the files locally (I recommend keeping all your Salesforce projects in one folder) and then hit create. Once the files have been created, it’s time to connect to your Org.

Authenticate with an Org

Use CMD + Shift + P (CTRL + Shift + P Windows) enter SFDX: Authorize an Org and hit enter.

Then select the type of Org to which you are connected.

Then give it a name again. I’ll use VSCodeExample. You will then be redirected to a Salesforce login where you will be asked to enter your credentials. Once you have logged in, you will be asked to Authorize VSCode—and once you hit allow, you’ll have access to your org! Your VSCode should look something like the picture below, once completed.

Getting all the Files from your Org

Now that our settings are connected, let’s get our existing code from the Org. In the left panel, you will see a folder called Manifest. Open it and right click on the file package.xml. Then click on retrieve source in Manifest from Org. This will download all your Org code files to your local machine. If I click into the folder force-app, I can then select the folder for the type of file for which I’m looking; in this case, an Apex Class. I select the classes folder and open the file SiteLoginController.cls. 

If I want to create a new class, I can use CMD + Shift + P (CTRL + Shift + P Windows) enter SFDX: Create Apex Class and give it a name. Once I hit enter, this file will be created locally, in the folder for that type of file. Once I’m ready to push it to the org, I can hit CMD + S and save it, or right click on the file and select deploy to Org. After saving or clicking deploy, you should see a success message or an error message explaining why the deployment failed.

Some Important Features

On the left panel, when in a Salesforce project, VSCode will have two additional buttons. The first addition is shaped like a chemistry beaker. Clicking on this will show the test classes and their status.

You may need to hit the refresh or play button next to the ApexTests panel to retrieve your test files. You must have test retrieval turned on for this to work. From here, you can run individual tests or test classes. After you’ve run a test, you can see the coverage in the console window. You can also use the 3 lines on the bottom panel of VSCode to show line coverage of an individual file; more on this later! You can also run tests from inside your test class. Inside of your test class, when you add @Istest, it will create a link you can click to run your tests. 

The second addition included to the left panel is an Org Browser. Here you can search for settings and different items inside of your Org.

The bottom panel of VSCode will show you some important information of which you should be aware. On the left part of this panel, you will see the name of the Org to which you are connected. You can change this at any time by clicking on the Org name and selecting a new one you’ve authorized. 

On the left side, you’ll also find a window button. This button when clicked will open up the Org you’re connected to in your default browser. This is great for when you need to jump into the Org to make a change on the admin side. 

The three-lines button on the bottom left of the panel is a handy tool as well. When looking at your class, you click this button to show the lines of code that have coverage (green) and the lines that don’t (red). You can toggle this off and on as needed.

A Final Word of Caution

Beware that without any other setting turned on when you deploy or retrieve you are overriding the org or your local version of the file. This means that if you’re working on a team, you can overwrite each other’s work. This can be prevented by only working on specific files, using the new conflict settings in VSCode, or by implementing source control. 

We’ve only scratched the surface of using VScode with Salesforce and there are many other customizations you can make. Salesforce is always rolling out new features to make our developer lives easier, so it’s important to see what new features Salesforce rolls out with each release. But for now, you should have VSCode and your org completely setup to begin development.

Need Help Navigating VSCode Development?

At Shift3 Technologies, we use a consultative approach to help you determine the best strategy to identify your challenges, implement appropriate solutions and enhance your systems. Need a consultation regarding VSCode development? Give us a holla! Trying to get your admins to love Salesforce? Check out our 3-part series!  For a free consultation, email [email protected] or call 559 560 3300 today.

Christian Coelho is a Certified Salesforce Admin and a Salesforce Developer focusing on APEX and API Integrations at Shift3 Technologies. When he’s not streamlining and automating workflows for clients, Christian spends time remembering how much he enjoyed line dancing, going to the movies and being at the beach.

Resources: Setup VSCode Trailhead / Start VSCode Trailhead

If you’re interested in uncovering the tech possibilities available to your organization or want to find more ways to increase your ROI with technology, click this link to schedule some time with one of our experts.