How to Enable Intellisense Support for Salesforce Apex Code in 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.

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 enable this feature for 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 above

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

Refresh sObjects Definitions

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 steps below-

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.

Test Intellisense Support

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.

How to Setup Visual Studio Code for Salesforce Development

In this post we will look into detailed steps to setup Visual Studio Code as IDE for Salesforce code development.

In the recent past, we have observed that Visual Studio Code (VS Code) is picking up popularity among open source IDEs for code development across multiple programming languages. JavaScript-based frameworks, Python-based application development, Salesforce Apex Code development, HTML, CSS based Front End development and so on are the most popular choices working with VS Code. This powerful behavior of supporting multiple platforms resides in the ability to adopt Plugins & Extension Packs that support the most popular programming languages & frameworks, and I believe Visual Studio Code has does a brilliant job so far.

In this post, we will look into detailed steps to setup Visual Studio Code as IDE for Salesforce code development. Here is the quick list of the components that we would be working through in the following sections-

  • Install & Configure Visual Studio Code
  • Install & Configure Salesforce CLI
  • Install & Configure Salesforce Extension Pack
  • Create Test Salesforce Project
  • Authorize Salesforce Org

We will discuss the individual configuration for each of the moving parts contributing to this setup in the upcoming steps-

Install & Configure Visual Studio Code

  • Click on “Download for Windows”
  • Save the setup file
  • Open the setup file by right click > Open. Please make sure you don’t use the “Run as Administrator” option since VS Code cannot be installed with Admin privileges as suggested by the following alert message.
  • Accept the License Terms and click Next
  • Click Next
  • Click Next
  • Make sure “Add To Path” is checked and click Next
  • Click Install
  • Wait till the setup completes the installation, which should be really a quick install
  • Click Finish & Launch VS Code to make sure installation works just fine

Install & Configure Salesforce CLI

  • Click “Download for Windows” depending on windows version you are running on
  • Save the CLI setup file
  • Open the setup file by right click > Open
  • Keep the defaults and Click Next
  • Keep the defaults and click Install
  • Wait till setup completes the installation, which should be really a quick install
  • Click Close to complete the installation

Install & Configure Salesforce Extension Pack

  • Launch VS Code
  • On the left most menu panel, Click Extensions Icon of press “Ctrl + Shift + X”
  • Search for “Salesforce Extension Pack”
  • Install Salesforce Extension Pack by clicking “Install” and wait till installation completes
  • Launch a new terminal by going to Terminal Menu > New Terminal or press “Ctrl + Shift + `”
  • Now we have to validate the installation of Salesforce CLI by typing “SFDX” in the new terminal. If we get the following similar outcome then we can ensure a successful installation.

Create Test Salesforce Project

  • Launch VS Code
  • Press “Ctrl + Shift + P” to see all available commands from all installed plugins & extensions
  • Search for “SFDX: Create Project with Manifest” and select it
  • Select project template as “Standard” or whatever suits you the best
  • Enter the desired name of the Project, whatever suits you
  • Select the folder location to save this project on the disk
  • And sure enough, we will get our new Salesforce project created with the manifest file

Authorize Salesforce Org

  • Launch VS Code
  • Press “Ctrl + Shift + P” to see all available commands from all installed plugins & extensions
  • Search for “SFDX: Authorize an Org” and select it
  • Select for “Org Url” Template, I will go by project default for this demo
  • Enter the Org Alias to recognize you Org by an alias, I have specified “SFOrg” as an alias for this demo
  • This process with direct you to the Salesforce Login Page, where you can specify the login credential for your Org (no matter Prod or Sandbox). Enter your credentials
  • Once successfully login to the Salesforce Org. visit the VS Code again and sure enough, we get the notifications to successfully authorize the Org.

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.