Generative AI is a transformative technology that increases developer productivity, accelerates software application development, and reduces the barrier for anyone to learn programming. At this year’s TrailblazerDX, we announced Einstein for Developers – and now, Salesforce’s generative AI solution that unleashes developer productivity, is officially in Open Beta.
Built specifically for Salesforce languages and frameworks, Einstein for Developers is able to generate Apex code using natural language. Support for LWC is coming soon. In this blog, we will explore how to get started with Einstein for Apex development and how its potential can revolutionize your development process.
Einstein for Developers vs. other AI coding tools
The generative AI coding tools available today are primarily trained on public languages, such as Java, Python, and others, as well as on publicly available code. Since Salesforce-specific languages like Apex and LWC are proprietary, these tools often lack the training to provide accurate recommendations.
Additionally, AI coding tools are only as powerful as the context provided to them. Since these public coding tools lack your org’s Salesforce context, such as metadata, recommendations may be inaccurate or insufficient to meet your needs. Lastly, using publicly available AI tools exposes your private code beyond the Salesforce trust boundary and could make it public — a potential security vulnerability.
With Einstein for Developers, we utilize CodeGen, our own open-source model for program synthesis. We host CodeGen within the Salesforce trust boundary and have trained it on Salesforce-specific languages like Apex and LWC. With dynamic grounding incorporated into the code generation process, Einstein enriches its recommendations using your metadata and code. Our AI trust layer within Einstein ensures that your data and code stay securely within Salesforce and are never stored externally.
Get started with Einstein for Developers
Einstein for Developers is currently in open beta. To enable Einstein for Developers in your org, navigate to Set up | Einstein for Developers toggle enable and accept terms.
Once enabled, install the Einstein for Developers Visual Studio Code extension on your VS Code Desktop. Einstein will also be available in Code Builder, our web-based IDE, which is expected to be generally available in October. Stay tuned for updates!
To utilize the Einstein for Developers tool effectively:
- Open your VS Code, go to File > Open Folder in the menu, and either open an existing Salesforce DX project or set up a new project.
- To work with Einstein for Developers, execute the SFDX: Authorize an Org command to connect to a Salesforce sandbox org or scratch org. You will be able to use Einstein for Developers within this environment.
If you are using scratch orgs, activate Einstein for Developers by enabling the add-on scratch org feature. Simply edit and save the config/project-scratch-def.json file in your DX project and add the EinsteinGPTForDevelopers
feature to your existing feature list.
For Example:
Finally, you can start generating Apex code by writing a prompt using one of these methods:
- Using the Einstein Sidebar from the Activity bar as shown below
- Using the Command Palette command: SFDX: Generate Code with Einstein (see screenshot below). Note that you need to be within an Apex file (
.cls
) for the command to appear.
Here is an example prompt:
I want to create an Apex class. Let’s call it OpportunityQuerySelector. Create a method named getSumOfOpportunityRecords that retrieves the number of opportunity records linked to a specific Account record. The method should accept accountId as the parameter. Follow security best practices and ensure the code runs in the user mode
And then the output is shown below.
While the above-generated code above did not require many edits, you may need to customize the Einstein-generated output to your needs during development. The Einstein: History and Feedback panel within the IDE allows you to share feedback about the generated output — this feedback is imperative in helping us train our LLM and improve your output! We’re excited to hear your feedback.
Transforming the development process
We are just getting started with generative AI to transform your development workflow. See what’s coming soon:
- Lightning Web Component (LWC) support: Generate LWC code based on natural language processing (NLP)
- Predictive in-line code completion: Automatically fill in the next line of code that’s suggested with contextual project metadata
- Code performance check: Scan Apex code and fix runtime errors during the development process
- Conversational assistance: Ask Einstein to generate contextual code and documentation, explain code, or solve complex problems
Conclusion
As Einstein for Developers expands its capabilities to support LWC, provide intelligent code completion, and deliver conversational assistance, you will be able to build on the Salesforce Platform faster than ever before. Try the beta today and join us at Dreamforce ’23 to dive deeper into Einstein for Developers!
Further Resources
- Einstein for Developers Documentation
- Einstein for Developers: Ask me Anything
- Einstein for Salesforce Developers blog post
About the author
Mohith Shrivastava is a Developer Advocate at Salesforce with a decade of experience building enterprise-scale products on the Salesforce Platform. Mohith is currently among the lead contributors on Salesforce Stack Exchange, a developer forum where Salesforce Developers can ask questions and share knowledge. You can follow him via LinkedIn.