How to Enable Intellisense Support for Salesforce Apex Code in Visual Studio Code

How to Enable Intellisense Support for Salesforce Apex Code in Visual Studio Code 

Introduction 

I am sure we all know how painful it can be to write code without Intellisense support for the code editor. Therefore, it is really important to see how we can add this feature to our favorite code editor, Visual Studio Code.

In this blog, we will look into how to enable Intellisense support for Salesforce metadata. Enabling this feature will increase code writing capability and accuracy exponentially for developers.

Salesforce provides IntelliSense support by implementing “Apex Language Server” through Salesforce CLI. “Apex Language Server” is dependent on Java as its prerequisite.

Let’s start by downloading and installing the Java Runtime Engine which we can download from the Java Development Kit.

Download Java Development Kit

Step 1

Download the JDK version, as shown below:

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Step 2

Once the download is complete, we can install JDK using Administrator privileges:

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Step 3

Click Next

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Step 4

Keep defaults and click Next.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Step 5

Wait until the installation files are copied.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code 

Step 6

Keep defaults and click Next.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Step 7

Wait until the installation is completed.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Step 8

Click Close to complete the installation.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Configure User Settings in Visual Studio Code

Launch Visual Studio Code and follow the below steps:

Step 1

Use shortcut “Ctrl + Shift + P” to launch the Command Palette

Step 2

Search for “User Settings”

Step 3

Run the command “Preferences: Open User Settings”

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Inside the User Settings, follow the below steps.

Step 1

Search for a User Property “Java: Home”

Step 2

Locate the property “Salesforcedx-vscode-apex > Java: Home”

Step 3

Specify the installation path of JRE folder, in my case, it is “/Program Files/Java/jre1.8.0_231”

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

As soon as we are done with the steps above, we need to follow the below instructions.

Step 1

Click on the output Tab in the terminal window.

Step 2

Select “Apex Language Server” from the Output. If you see a message coming through, that means that “Apex Language Server” is up and running.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Now, the next thing to do is to refresh sObject Definitions from Salesforce Dev Org or Sandbox to the local Definitions cache.

To refresh the sObjects Definition, we need to first close User Settings Window and use the shortcut “Ctrl + Shift + P” to launch the Command Palette.

Then follow the below steps.

Step 1

Search for the “SFDX: Refresh SObject Definitions” command.

Step 2

Click “SFDX: Refresh SObject Definitions”

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code 

Step 3

Select what type of SObject Definitions you want to refresh. I would recommend selecting “All SObject”, since this will be the most effective option to refresh the definition cache all at once for the complete Salesforce Org

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Step 4

After you make the selection, look for the Output window in the terminal where we can see this Refresh Process has started successfully, as shown below.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Step 5

After a short wait, you can look for the Output window again. If everything goes as expected, you will see the process has completed successfully, with exit code 0. Exit Code 0 means that no errors have been encountered. If it encountered an error, the respective error code would have been returned.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

That is all for the configuration. Now it is time to test if Intellisense is enabled as expected.

Let's create an Apex test code to see if we get Intellisense support. Here I have added a trigger, as shown below.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

We can see that Intellisense support is available.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Happy Coding.

How To Enable Intellisense Support For Salesforce Apex Code In Visual Studio Code

Hope you enjoyed this article. Please leave your comments below to let me know how you like the content and how you find it helpful for learning the topic.


Similar Articles