Salesforce development with Visual Studio Code

Visual Studio CodeLeave a Comment on Salesforce development with Visual Studio Code

Salesforce development with Visual Studio Code

Developing for Salesforce is something I usually try to avoid. Salesforce is an off-the-shelf product, which you can tailor to your needs and wishes by changing things in the Setup. For most organizations, the functionality that is available straight out of the box will be enough. Sometimes you want a bit more, and that is where the development part steps in.

There are several options for developing for Salesforce. You could simply use the Developer Console that Salesforce provides. This is a simple text-editor, that will be sufficient for small changes. But as a developer you want a bit more, you want syntax highlighting, auto complete names of functions, methods, variables. In my opinion, Visual Studio Code with the Salesforce Extension Pack is the way to go now.

If you want to start using Visual Studio Code with Salesforce, you have multiple ways to get started. One way is follow the Trailhead that describes it, which I did too. Yay, more badges! Another way is just trying it out, if you’re familiar with Visual Studio Code, it will be very easy.
I’ve been working with it for a while now, and I find it that good to work with, that I want to spread the word!

Install it all

So, getting started. You’ll first need Visual Studio Code (I’ll call it VS code from now on, no need to use the long name anymore) of course, which you can get here. It also requires Salesforce CLI, if you don’t have that yet, that is available here.
After installing those both, start VS Code. Click on Extensions in the bar on the left, search for Salesforce in the window that appears. Click on ‘Salesforce Extension Pack’, and there, click Install.

After it has been installed, go back to the Explorer. Open the Command Palette (CTRL + SHIFT + P on Windows) and go to “SFDX: Create Project with Manifest”. This is the option you use if you want to connect to a Playground, Sandbox or Developer Edition org. For Scratch Org’s you’ll use “SFDX: Create Project”. For my explanation we’re going with the manifest one.
It will ask you to fill in a name, put in a name you’ll recognize.

A explorer window will be opened, asking you to select a folder where you want to save the project. It will create a folder with the name of the project, within the folder you’ll select. So if you choose “C:\development”, it will create “C:\development\projectname”.

Connecting to an Org

When setting up the project locally is done, you’ll go and connect your project with the Salesforce org you want to develop in. To do this, open the Command Palette again and choose “SFDX: Authorize an Org”. A list will appear asking you where you want to login. For a Sandbox org you should select ‘’, for a Playground you can use the default one ( In the next field you can put in a name for the org, this is a name that will be saved in the project configuration. You can choose any name that will help you in remembering which org it is.
It will then open a Salesforce login window, login here with your Salesforce org credentials. In the next Window, it’ll ask you to allow several permissions for VS Code, click Allow and return to VS Code. You’re now connected to your Org, and you can actually develop from VS Code!

Getting the current Apex Classes, Triggers, Visualforce Pages, etc., is of course important. In your explorer view, right click on the package.xml under the folder manifest and select “SFDX: Retrieve Source in Manifest from Org”. This will retrieve all that is already present in the org. After it has retrieved everything, you will find these files in the folders under “\force-app\main\default”.
But of course, you don’t only want to change existing code, you also want to create new functionality. To create new files, open the Command Palette again and start to type “SFDX: Create”. It will auto-complete and show a list of all commands for SFDX that will help you create new files. For example a new Apex Class. If you select any option, it will ask you to put in a filename. When you have done that, press Enter and it will create your file. It’s as easy as that!

Start actual development

After you have put in your classes, methods, variables, whatever you want to create, you want to have it in your Org of course. Again, that is where the Salesforce Extension Pack helps you!
From any file you have open and want to have in your Org, after making sure you’ve saved it, right click in the file and choose “SFDX: Deploy This Source to Org”. It will deploy your source to the connected org, and will display a message when it has been deployed.

For simple, small changes, you’ll might still want to use the developer console now and then. But for actual development, creating classes, pages, you will not want to do anything else than using VS Code. If you’re going to create Lightning Web Components, you have to use an external editor such as VS Code. At this moment, you cannot create/change those from Salesforce itself.

Your new way of working?

For me, using VS Code has changed, and improved, my way of working. Before I was creating Apex Classes from the Developer Console, but now even for Trailheads I’m connecting VS Code to the Playground whenever I have to do some coding. It only takes a minute to setup, once you know how, and it helps you immensely.
Will it also be your new way of working?

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top