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


I am sure we all know how painful it could be writing code without Intellisense support for the code editor. So 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 the detailed steps of how to enable Intellisense support for Salesforce metadata. Enabling this feature will increase the code writing capability and accuracy exponentially for a developer.

Salesforce provide intellisense support by implementing “Apex Language Server” through Salesforce CLI. “Apex Language Server” is dependent on java as its prerequisite.

Lets’ start by downloading and installing Java Runtime Engine that we can download from Java Development Kit

Download Java Development Kit


Step-1: Download the JDK version as shown


Step-2: Once the download is complete, we can install the JDK by using Administrator privileges


Step-3: Click Next


Step-4: Keep defaults and click Next


Step-5: Wait till the installation files copied


Step-6: Keep defaults and click Next


Step-7: Wait till the installation completes


Step-8: Click Close to complete the installation



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”




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”



 As soon as we are done with the steps above we need to follow the steps below-

Step-1: Click on the output Tab in the terminal window

Step-2: Select “Apex Language Server” from Output down as shown, if you find message coming through that mean “Apex Language Server” is up and running



Now 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 following steps-

Step-1: Search for “SFDX: Refresh SObject Definitions” command

Step-2: Click “SFDX: Refresh SObject Definitions”



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
  


Step-4: After you make the selection, look for Output window in the terminal where we can see this Refresh Process started successfully as shown 


Step-5: After a short wait you can look for the Output window again and if everything goes as expected you will the process completed successfully with exit code 0. Exit Code 0 means no errors encountered if it encountered any error the respective error code would have returned.



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

Lets’ create any apex test code to see if we get Intellisense support, here I have added a trigger as shown below-



We can see the Intellisense support available.



Happy Coding.   


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

Trailblazer Profile | LinkedIn | Salesforce Blog | Facebook | Youtube Channel | WhatsApp Community

Comments