Use the Command Palette to Generate Apex Code
You can quickly access Agentforce 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 Agentforce: 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 Agentforce 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.
To access the Agentforce: Generate Code command through hotkeys, press Cmd+r (macOS) or Ctrl+r (Windows or Linux). You can customize these shortcuts. See Keyboard Shortcuts editor.