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.
  • Select the length of inline completions.
  • Use Agentforce for Developers to write Apex 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.

Choose Your Inline Autocomplete Settings

To use the Inline Autocompletions tool, make a few selections in Settings. In VS Code or Code Builder, select File | Preferences | Settings (Windows or Linux) or Code | Settings | Settings (macOS). Search for Autocompletions to see the autocompletion settings for Agentforce for Developers.

  1. Turn autocompletions on or off by toggling the Enable Autocompletions checkbox.​​
  2. Choose the file type (Apex, Javascript, CSS, or HTML) for the autocompletions.
  3. Choose between long or short completions. Long completions help you with more complex coding tasks. Short completions help you keep coding quickly.

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 Einstein.

Write a Unit Test for Your Apex 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.

  1. In a method in an open Apex class, right-click and select Einstein: Generate A Test. Or just click the beaker icon () on the top right of the open file.
  2. Select the method for which you want to generate unit tests.
  3. When you’re prompted, you can select an existing test class 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. Review the generated unit test method, and choose to keep it or start all over.
  5. To generate another test method, right-click within the class file or the test class file, and again select Einstein: Generate A Test.
  6. Select one or more methods for which you want to generate a test. Agentforce uses the context of existing tests to create new tests that do not duplicate the code that you already have! Select only the tests you want to inform Agentforce for Developers about, and then click OK.
  7. Again, review the generated unit test method and decide if you want to use it or start all over.

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

Salesforce 도움말에서 Trailhead 피드백을 공유하세요.

Trailhead에 관한 여러분의 의견에 귀 기울이겠습니다. 이제 Salesforce 도움말 사이트에서 언제든지 새로운 피드백 양식을 작성할 수 있습니다.

자세히 알아보기 의견 공유하기