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:
| Attribute | Meaning | CLI equivalent |
|---|---|---|
program | test (the default) or exec | The aer test or aer exec command |
sourcePaths | Directories containing the Apex source | Source path arguments, or --path for aer exec |
filter | Test to run: ClassName or ClassName.methodName | --filter |
skip | Tests to skip | --skip |
integrationTests | Run @IntegrationTest methods instead of @IsTest methods | --integration-tests |
assignPerms | Permission sets to assign to the default user | --assign-perms |
defaultNamespace | Namespace for the loaded code | --default-namespace |
packageDir | Directory containing .pkg files | --package-dir |
timezone | Time zone for date and time operations | --timezone |
sandbox | Run in sandbox mode | --sandbox |
bootstrapDb | SQLite database to seed before running | --bootstrap-db |
aerPath | Path to the aer executable | |
args | Additional command-line arguments | Added to the command line as written |
stopOnEntry | Stop 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
| Setting | Default | Meaning | CLI equivalent |
|---|---|---|---|
aer.path | aer | Path to the aer executable | |
aer.useSfdxProject | true | Read source paths, namespace, and replacements from sfdx-project.json | |
aer.sourcePaths | [] | Directories containing Apex source | Source path arguments, or --path for aer exec |
aer.defaultNamespace | Treat the loaded code as belonging to this namespace | --default-namespace | |
aer.packageDir | Directory containing .pkg files to load | --package-dir | |
aer.assignPermissionSets | [] | Permission sets to assign to the default user before running tests | --assign-perms |
aer.timezone | Time zone for date and time operations, such as America/Los_Angeles | --timezone | |
aer.sandbox | false | Run in sandbox mode | --sandbox |
aer.bootstrapDatabase | SQLite database to seed before running or debugging tests | --bootstrap-db | |
aer.lsp.trace | off | Trace 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:
packageDirectoriesbecome the source paths passed to the language server, the test runner, watch mode, and the debugger.namespacebecomes the default namespace.replacementsare applied by copying the source into a temporary directory with the substitutions made before running, matching whatsf project deploy startwould deploy.replaceWithEnv,replaceWithFile,replaceWhenEnv, andallowUnsetEnvVariableare 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.pathis loaded alongside the packaged source. apexTestAccess.permissionSetsare passed to aer as--assign-perms, together withaer.assignPermissionSets.apexTestAccess.permissionSetLicenseshas 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 --versionworks in a terminal, or setaer.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.tracetoverboseand read the aer Language Server Trace output channel.