Natural Language to Code Generation
Natural Language to Code Generation
Generate Apex Code from Natural Language Prompts
Use the Einstein for Developers sidebar to write a question or an instruction that describes the task for which you’d like to receive an Apex code suggestion and press Ask. Copy the code suggestion you received and paste it into an Apex file to use as “starter” code.
Use the Command Palette to Generate Apex Code
You can quickly access Einstein for Developers from inside an Apex file in the VS Code editor.
- Open an existing Apex (
.cls
) file, or create one from the command palette by running the SFDX: Create Apex Class command. - Put your cursor on the line in the file where you want the generated code to be placed.
- From the Command Palette, run Einstein: Generate Code.
- For your query, enter a description of the code that you want to generate. For example, “
Write a method that takes an account as a parameter and returns all contacts associated with that account.
” - Review the code that Einstein generates, and then click Accept, Try Again, or Clear.
Use our example prompts to learn how to get the most out of the generative AI tool.
Tip: To access the Einstein: Generate Code command through hotkeys, press Cmd+r (macOS) or Ctrl+r (Windows or Linux). You can customize these shortcuts. See Keyboard Shortcuts editor.
You can customize these shortcuts. See Keyboard Shortcuts editor.