Einstein for Developers

A Visual Studio Code Extension for Salesforce Developers

Tanmay Verma
Globant
4 min readMay 28, 2024

--

Source: Salesforce

Salesforce Einstein is an AI platform created by Salesforce. It uses advanced machine learning to analyze large amounts of customer data and provides valuable insights, predictions, and recommendations. This article explains how to add the “Einstein for Developers” extension in VS Code and leverage its capacity to write code faster.

About Einstein for Developers

The “Einstein for Developers” extension uses AI and helps developers by writing code as per the prompt. It gives coding suggestions using line autocomplete and writes test classes. This VS Code extension uses Salesforce’s CodeGen, and boosts efficiency and offers valuable support to developers. To use it, the Salesforce org you want to use must have enhanced domain enabled.

This extension supports the following Salesforce Org editions. They are Developer, Enterprise, Partner Developer, Performance, and Unlimited Editions.

Prerequisites for adding Einstein for Developers Extension in VS Code

Before we go ahead to add the “Einstein for Developers” extension, we need to complete the below prerequisites in VS Code :

  • The developer should have access to a Salesforce org with Einstein for Developer enabled.
  • VS Code setup should be there with version 1.76 or later.
  • The Salesforce Extension pack should be installed in VS Code.
  • Java 11 or Java 17 should be installed.

Adding Einstein for Developers Extension in VS Code

The below steps will help in enabling the extension in VS Code.

  1. Go to the extension of VS Code and search for “Einstein for Developers”.

2. Install the extension.

Image 1: Einstein for Developers Extension

3. a new icon will be enabled in VS Code after successful installation.

Image 2: Einstein icon added in VS Code

Usage of Einstein for Developers Extension

The below sections will explain the usage of the “Einstein for Developers” Extension in VS Code.

For Code Generation

  • After the successful installation of the extension, a prompt box will appear. It will have the label “Enter Prompt” in the sidebar. The developer can write the requirement to write any method or to write a SOQL query and the developers will get the result.
Image 3: Code generator based on prompt
  • The extension will also help the developer write the code in an Apex class or LWC. To do so, the developer needs to open an Apex class. Then, go to the command palette and search for “Einstein: Generate Code.”
Image 4: Command palette for Einstein: Generate Code
  • After that, ask the developer to write the requirements that Einstein can assist with. Einstein will write the logic and will ask either to Accept, Try again, or Clear.
Image 5: Method generated by Einstein

For Inline Autocomplete of code

The Einstein for Developers extension is helpful for any developer. It is for those working on Apex and LWC (Javascript, CSS, and HTML). This extension gives multiple suggestions to complete the code, which the developer can pick up while coding.

In the below image, the extension will help by suggesting the Apex class :

Image 6: Einstein suggested for Apex development

In the below image, the extension will help by suggesting for the Javascript of LWC :

Image 7: Einstein suggested for JS of LWC.

For Test Class Generation

When the developer wants to write the test class, go to the command palette. Search for “Einstein:Generate a Test”. Then, there will be an option to select either “Create a new file” (for a new Apex class) or select any existing test class.

After confirmation, a test class and test method will be created. The developer can review and deploy the test class to the org (sandbox).

Image 8: Einstein generated test class and method along with Run Test option

After the test class deploys, a developer can run a single test method or the whole test class from VS Code.

Once the test class execution is completed, the results will be shown, as below:

Image 9: Summary of Run Test

Keep In Mind

The “Einstein for Developer” extension will speed up development. But, it is also suggested to review the generated code. Do so based on your project’s best practices. This includes things like variable declaration and test data generation. You can use any existing DataFactory class, etc.

Conclusion

This VS Code extension is helpful for anyone with basic development knowledge who wants to write code with AI’s help. It will save developers time by helping them generate and complete code quickly. It can also be used to generate test cases.

--

--