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.

  1. Open an existing Apex (.cls) file, or create one from the command palette by running the SFDX: Create Apex Class command.
  2. Put your cursor on the line in the file where you want the generated code to be placed.
  3. From the Command Palette, run Agentforce: Generate Code.
  4. 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.
  5. 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.