Skip to main content

Speed Development with Autocompletions and Apex Test Generation

Learning Objectives

After completing this unit, you’ll be able to:

  • Access Inline Autocomplete.
  • Explain how to access code suggestions.
  • Use Agentforce for Developers to write Apex and LWC unit tests.

Get Coding Help with Inline Autocompletions

The AI-powered Inline Autocompletions tool makes your development experience easier and more efficient. It works with Apex and LWC (JavaScript, CSS, and HTML) files. Inline Autocomplete suggests code completions for you within your editor, so you don’t ‌spend time searching for the right syntax. While it’s at work, a tiny sparkle ✨ in your editor lets you know that Agentforce is getting ready to come up with suggestions. Just browse the handful of code suggestions and accept the one that works best for you.

When writing code, you're often doing things like assigning variable values to an SObject such as Account.name = 'abc' in Apex, or writing SOQL to query for product attributes. Pause the cursor in your code and watch Agentforce for Developers suggest a completion and fill out the remaining code in grayed (ghost) text.

VS Code window showing an autocompletion.

You can also manually trigger an autocomplete using the Option (⌥)\ hotkeys for Mac and Alt+\ for windows. To view other hotkeys, go to Settings | Keyboard Shortcuts and search for Agentforce.

Write a Unit Test for Your Apex and LWC Code

If you’re an Apex programmer, you know the rules: Unit tests must cover at least 75% of your Apex code. All of those tests must pass before you can make your code available or package it for AppExchange. Now you can use Agentforce for Developers to quickly generate unit tests for your Apex classes!

Here’s how to use the tool to generate an Apex unit test.

  1. In a method in an open Apex class, right-click and select Agentforce: Generate an Apex Test. Or just click the beaker icon () on the top right of the open file. This opens the Test Case Generation panel with the Apex file name pre-populated.
  2. Select the method for which you want to generate unit tests.
  3. Select an existing test file or create a new one. If you create a new test class, the command names the new file, <ApexClassFileName>Test.cls. It then adds the test method to the new file.
  4. Click Generate to generate a unit test.
  5. Review the generated unit test method, and choose to Regenerate, Discard or Accept.

When you generate another test, Agentforce uses the context of existing tests to create new tests that don't duplicate the code that you already have!

This module gave you an introduction to the world of Agentforce for Developers. You’re now prepared to use what you've learned as you continue on your journey as a Salesforce developer, with more modern tools at your disposal. Onward!

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback