How To Power Up SFDX-CLI with VS Code Remote SSH and Speed Up Salesforce Development
I do my Salesforce coding work from any VS Code-compatible workstation, switching between Mac, Windows and Linux depending on my circumstances. I get this done with a remote server computer, the Salesforce VS Code Extension Pack, the VS Code Remote – SSH extension, and the VS Code Settings Sync feature. This setup makes using SFDX-CLI in a standard Ubuntu Linux environment simple and transparent, which speeds up my daily developer workflow.
- Leverage The Power of VS Code Remote – SSH
- Goal: Org-Based Developer Workstation
- Workstation Setup
- Set Up VS Code Remote Server – SSH for SFDX-CLI
- Create First Project
- Enable VS Code Settings Sync
- Secure and Accelerate Your Development
Leverage The Power of VS Code Remote – SSH
VS Code Remote – SSH is an exciting feature of VS Code because it lets developers use shared server resources to simplify workstation setups and accelerate devops pipelines.
This VS Code feature uses a high-performance backend server running standard Linux and where each user has their own login and home directory. For Salesforce developers, using a remote server simplifies the use of Java for the Apex language server, eliminating the need to install Java on individual workstations.
Here is how it works. My workstation connects to a VS Code daemon running on the server. The server then takes over the bulk of VS Code extension processing needs, such as running the Apex language server and Java. The workstation is left to handle the VS Code user interface. This architecture reminds me of the Sun UNIX X Terminal from the 1990s!
Key Benefits for the Enterprise
There are distinct benefits to the Remote – SSH architecture for enterprises. The main one being that new members of a development team do not have to set up their individual workstations to run their toolchains. It all comes pre-installed in the Linux shell environment on the server. Another benefit is the added power, speed, and general productivity gained from using a scalable backend.
In the SalesforceDevops.net lab I have some older Windows and Mac workstations. I managed to upgrade the developer experience for all these workstations by adding one shared, super-sized server computer running in the background. Now, with 16 Ryzen cores, 2 TB M.2 storage, and 128 GB power boost, NPM installs and VS Code fly like the wind, even on a five-year-old PC.
Let us dig into the steps needed to power up your Salesforce devops workflow with VS Code Remote – SSH.
Goal: Org-Based Developer Workstation
In this tutorial, I show how to set up a Windows 10 workstation and use VS Code Remote – SSH to connect an Ubuntu 20.04 Linux backend to create a more powerful developer experience. This setup procedure is designed for the Salesforce developer who wants to use source-based development techniques to modify existing orgs, which Salesforce refers to as “org-based development.”
To get the job done, I show you how to set up the network components, set up the VS Code workstation, and then finish up by downloading a predefined set of metadata.
To follow along with this tutorial, you need the Fira Code Retina font on your workstation. To install it please download the font collection and install the font file “Fira Code Retina.ttf”. This works on Windows, Mac, and Linux.
Next, set the terminal font in VS Code. Get that going by clicking on the Settings icon and search for “terminal font”. Enter “Fira Code Retina” and then close the Settings window.
This font is required because the Ubuntu shell enhancements installed later require a Powerline font to work properly. If you don’t like Fira Code Retina then you can install a different Powerline font.
Set Up VS Code Remote Server – SSH for SFDX-CLI
You may use a virtual machine or a bare-metal setup for your server. It can be in your local network or in the cloud, depending on your Internet connectivity and budget. In my case I use a bare metal server running the local LAN segment to eke out every bit of performance.
I will describe some of the major steps in this post. Please check out the video for the full tutorial. I put together a GitHub gist with all the steps summarized so you can follow along with the video.
Java is required to run the Apex language server on the remote server. Ubuntu comes with OpenJDK v8 JRE version of Java, which works with the Apex language server. To install and verify Java on Ubuntu 20.04 use these commands:
sudo apt install default-jre java -version which java
Note how the “java -version” command only has one dash. The “which java” command shows the Java path, “/usr/bin/java”, which we will need later.
Create User Account
Create a non-privileged account on the server for each user who is using VS Code Remote – SSH. Use this command to create a new user on the server:
sudo adduser vern
The adduser command issues a series of prompts, all of which can be answered by hitting RETURN.
Install SFDX-CLI for Each User
Each user on the server must have a separate NodeJS and NPM system installed within the user context. Plus, the Salesforce CLI, also known as SFDX-CLI, must also be installed for each user. All the steps required to do the setup are included in the video tutorial and the script.
For a gentler introduction to this setup procedure, please check out an earlier tutorial, How to Install SFDX-CLI on Ubuntu 20.04 to Boost Developer Productivity, for instructions on how to setup the ZSH shell and SFDX-CLI.
Windows SSH Key Setup
Windows 10 comes bundled with OpenSSH, but it lacks the “ssh-copy-id” command. This makes setting up an SSH key on for remote login on Windows trickier than on Mac or Linux workstations.
To prevent frequent password prompts with using VS Code Remote – SSH follow these steps. Substitute “devops” with your remote hostname and “vern” with your remote username.
PS> ssh vern@devops $ mkdir ~./.ssh $ touch ~/.ssh/authorized_keys $ logout PS> ssh-keygen # (press ENTER for all prompts) PS> type C:\Users\user\.ssh\id_rsa.pub | ssh vern@devops 'cat >> .ssh/authorized_keys'
Setup VS Code for Remote Salesforce Development
These are the minimum extensions required to do Salesforce development using VS Code Remote – SSH:
Next, setup the remote connection:
1. VS Code Command: Remote SSH: Add new SSH host… 2. Enter in prompt: vern@devops -A 3. Acknowledge any MAC address security prompts 4. Select Linux as the server type
Test the connection by typing
CTRL-~ to bring up a terminal prompt.
Install VS Code Extensions on Remote
Perform these steps to install the Salesforce extensions on the remote server.
1. VS Code Command: Install Local Extensions in 'Remote' 2. Select all available extensions for installation 3. Click Install
Create First Project
With VS Code remotely logged on to the server, use
CTRL-~ to open a terminal prompt on the remote server. Run these commands to create your first project. When running step #3 follow the supplied prompts to log onto the web to complete the authentication process.
sfdx force:project:create --projectname=mybranch –manifest cd mybranch sfdx auth:device:login --setdefaultusername --setalias myUser sfdx force:source:retrieve --manifest=manifest/package.xml
Finally, use the VS Code File-Open Folder command to find the “mybranch” directory. Enter that directory and select it. That opens your window showing the source code tree. Use
CTRL-~ again to open a terminal prompt, and you are ready to go!
Enable VS Code Settings Sync
The VS Code settings sync segment is not included in the video, but VS Code Settings Sync is what makes the multi-workstation technique work smoothly! Until its introduction, the pain of re-installing needed extensions, font settings, etc. was a real deterrent to smooth operation of VS Code Remote – SSH for me.
The VS Code Settings Sync feature is still technically in beta, but I recommend its use. A GitHub or Microsoft account is required to use VS Code Settings Sync. To get started hit F1 and run this VS Code command:
1. VS Code Command: Settings Sync: Turn On
A wizard takes you through some options, and then asks you to log onto either GitHub or Microsoft. From that point forward, VS Code Settings Sync works in the background without further attention. You just need to log onto Settings Sync with the same account on another workstation, and your settings will sync automatically.
Secure and Accelerate Your Development
Using remote servers can not only boost your daily Salesforce developer productivity, but with source code and system configurations maintained within a security perimeter, software supply chain security goes up. Enterprise architects and power-hungry developers take note — VS Code Remote SSH accelerates your Salesforce devops pipeline.