VS Code

The aer Local Apex Debugger extension for VS Code runs and debugs Apex tests with aer, shows code coverage in the editor, and provides Apex language features through aer’s language server.

Install

Install aer Local Apex Debugger from the Visual Studio Marketplace, or search for it in VS Code’s Extensions view. It requires VS Code 1.88 or later.

The extension runs the aer executable on your PATH, or the one the aer.path setting names. If it cannot find one, it offers to download the latest release. It checks for newer releases periodically and offers to update the copy it downloaded. A downloaded copy is added to the PATH of terminals you open in VS Code afterwards, after the existing entries, so an aer installed elsewhere on your PATH still takes precedence.

Language features

The extension starts the aer language server when you open an Apex file (.cls, .trigger, or .apex):

  • Semantic syntax highlighting
  • Autocompletion (Ctrl+Space)
  • Hover information for classes, methods, SObject fields, and relationships
  • Go to definition (F12)
  • Find references (Shift+F12)
  • Document symbols (Ctrl+Shift+O)

A .apex file opens as anonymous Apex.

Testing view

The extension lists your tests in VS Code’s Testing view under an aer node, split into Unit Tests (@IsTest) and Integration Tests (@IntegrationTest). Use the run or debug icon next to a method, class, or group to run that scope. Results appear inline and in the Testing panel with pass or fail status, durations, and error messages linked to file locations. A test with no result, for example because the run was stopped first, is marked skipped.

Four run profiles are available:

  • Run Apex Tests runs the selected tests.
  • Run Apex Tests with Coverage runs them with coverage. Covered and uncovered lines are marked in the editor gutter, and per-file totals appear in the Test Coverage view and the Explorer. Only the classes the selected tests exercise are reported.
  • Debug Apex Tests starts the selected tests under the debugger, stopped on entry.
  • Watch Apex Tests runs the selected tests and runs them again each time a .cls, .trigger, .pkg, or flow file changes. Cancel the run to stop watching.

Integration tests commit their data and run @TearDown cleanup. A selection that includes both kinds runs as two runs, unit tests and then integration tests, and coverage from both is merged, with a line counted as covered when either run executed it. Because each integration test starts its own debug session, debugging everything skips integration tests; debug one by selecting its class, method, or the Integration Tests group. When a workspace has both kinds, the debug action on the top-level aer node is hidden.

Debugging

Debug a test from the Testing view, or press F5 with a launch configuration in .vscode/launch.json. Add one with the Apex: Debug Tests (aer) snippet:

{
	"version": "0.2.0",
	"configurations": [
		{
			"type": "aer",
			"request": "launch",
			"name": "Debug Apex Tests",
			"sourcePaths": ["${workspaceFolder}/force-app/main/default/classes"],
			"stopOnEntry": true
		}
	]
}

To debug anonymous Apex, set "program": "exec" and pass the code in args. An input variable prompts for it when the session starts:

{
	"version": "0.2.0",
	"configurations": [
		{
			"type": "aer",
			"request": "launch",
			"name": "Debug Anonymous Apex",
			"program": "exec",
			"stopOnEntry": true,
			"args": ["${input:apexCode}"]
		}
	],
	"inputs": [
		{
			"id": "apexCode",
			"type": "promptString",
			"description": "Enter Apex code to execute:"
		}
	]
}

A launch configuration accepts these attributes. Each one that has a matching setting overrides it:

AttributeMeaningCLI equivalent
programtest (the default) or execThe aer test or aer exec command
sourcePathsDirectories containing the Apex sourceSource path arguments, or --path for aer exec
filterTest to run: ClassName or ClassName.methodName--filter
skipTests to skip--skip
integrationTestsRun @IntegrationTest methods instead of @IsTest methods--integration-tests
assignPermsPermission sets to assign to the default user--assign-perms
defaultNamespaceNamespace for the loaded code--default-namespace
packageDirDirectory containing .pkg files--package-dir
timezoneTime zone for date and time operations--timezone
sandboxRun in sandbox mode--sandbox
bootstrapDbSQLite database to seed before running--bootstrap-db
aerPathPath to the aer executable
argsAdditional command-line argumentsAdded to the command line as written
stopOnEntryStop at the first statement

The extension starts aer test --debug or aer exec --debug as its debug adapter, speaking the Debug Adapter Protocol over stdin and stdout. Run from a terminal instead, the same commands open the browser debugger.

While stopped:

  • Breakpoints. Click the gutter to set or clear one. Breakpoints are verified when the session starts. Conditional breakpoints and logpoints are not supported.
  • Stepping. Continue (F5), Step Over (F10), Step Into (F11), and Step Out (Shift+F11).
  • Variables. The Variables view shows locals, instance fields (This), and static fields. Hover over an identifier to see its value.
  • Expressions. Add expressions such as accounts.size() to the Watch view, or evaluate them in the Debug Console.
  • Async jobs. Batch, queueable, and future jobs that anonymous Apex enqueues run before the session ends, so breakpoints in them are reached.

A launch configuration you write yourself uses packageDirectories and namespace from sfdx-project.json but does not apply replacements. Debug from the Testing view to debug with replacements applied.

Settings

SettingDefaultMeaningCLI equivalent
aer.pathaerPath to the aer executable
aer.useSfdxProjecttrueRead source paths, namespace, and replacements from sfdx-project.json
aer.sourcePaths[]Directories containing Apex sourceSource path arguments, or --path for aer exec
aer.defaultNamespaceTreat the loaded code as belonging to this namespace--default-namespace
aer.packageDirDirectory containing .pkg files to load--package-dir
aer.assignPermissionSets[]Permission sets to assign to the default user before running tests--assign-perms
aer.timezoneTime zone for date and time operations, such as America/Los_Angeles--timezone
aer.sandboxfalseRun in sandbox mode--sandbox
aer.bootstrapDatabaseSQLite database to seed before running or debugging tests--bootstrap-db
aer.lsp.traceoffTrace messages between VS Code and the language server (off, messages, verbose)

Without aer.sourcePaths or an sfdx-project.json, the language server finds the project root by looking above the open file for sfdx-project.json or package.xml, or uses the parent of a classes, triggers, or flows directory.

Project settings from sfdx-project.json

When aer.useSfdxProject is on, the extension reads sfdx-project.json at or above the workspace:

  • packageDirectories become the source paths passed to the language server, the test runner, watch mode, and the debugger.
  • namespace becomes the default namespace.
  • replacements are applied by copying the source into a temporary directory with the substitutions made before running, matching what sf project deploy start would deploy. replaceWithEnv, replaceWithFile, replaceWhenEnv, and allowUnsetEnvVariable are honored. Failure locations map back to your files, and in watch mode your edits are copied into the temporary directory. The language server works on your files, so it does not apply replacements.
  • Each package directory’s unpackagedMetadata.path is loaded alongside the packaged source.
  • apexTestAccess.permissionSets are passed to aer as --assign-perms, together with aer.assignPermissionSets. apexTestAccess.permissionSetLicenses has no local equivalent and is ignored with a warning.

Explicit aer.sourcePaths and aer.defaultNamespace settings take precedence. Set aer.useSfdxProject to false in .vscode/settings.json to ignore the file.

Licensing

A debug session without an active aer license ends after five minutes. When aer reaches a license limit, the extension offers to subscribe, register a license, show the current license, or manage your subscription. The aer: License Management command shows the same choices, aer: Show aer License shows the output of aer license show, and aer: Register aer License prompts for a registration key and email address.

Troubleshooting

  • “Failed to start aer”. Check that aer --version works in a terminal, or set aer.path.
  • “Failed to connect to aer debug server”. Check that the source paths contain Apex and that aer test <path> runs from a terminal.
  • Breakpoints not reached. Check that the breakpoint is on a line with executable code in a class the test runs.
  • Language server problems. Set aer.lsp.trace to verbose and read the aer Language Server Trace output channel.