Find file History
Pull request Compare This branch is 60 commits ahead, 7 commits behind develop.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
.vscode
images
out
resources
scripts
snippets
src
syntaxes
test
.vscodeignore
LICENSE.txt
README.md
coverconfig.json
package.json
package.nls.json
tsconfig.json

README.md

Apex for Visual Studio Code

View outlines of Apex classes and triggers, see code-completion suggestions, and find syntactic errors in your code. This extension is powered by the Apex Language Server.

For best results, do not install this extension directly. Install the complete Salesforce Extension Pack instead.

Prerequisites

Before you set up this extension, make sure that you have these essentials.

View Code-Completion Suggestions

To see code-completion suggestions, press Ctrl+space when you’re working in a .cls or .trigger file. To navigate between the suggestions, use the arrow keys. To auto-complete a suggestion from the list, press Enter.
Animation showing code completion of a System.debug() statement

Insert Code Snippets

To see available Apex code snippets when you’re working in a .cls or .trigger file, run Insert Snippet. Snippets are available for class and interface definitions, a variety of statements, and much more. These code snippets are also available as code-completion suggestions.

View or Jump to Definitions

You can preview, view, or go to definitions of:

  • User-defined Apex
    • Classes (from definitions of extending classes)
    • Constructors
    • Interfaces (from definitions of implementing classes)
    • Methods
    • Properties
    • Variables (local and class variables)
  • Standard objects
    • Fields (standard and custom fields)
    • Object definitions
  • Custom objects
    • Fields
    • Object definitions

(See the "Enable Code Smartness for SObjects" section of this README for information on working with standard and custom objects.)

To preview a definition, hold down Cmd (macOS) or Ctrl (Windows or Linux) and hover over the item whose definition you want to see.

To view a definition, right-click the item and select Peek Definition, or press Alt+F12.

To jump to the location of a definition, right-click the item and select Go to Definition, or press F12.
Previewing, viewing, and jumping to a definition

Find All References

You can find all references to user-defined Apex:

  • Classes
  • Class variables
  • Enums
  • Interfaces
  • Methods
  • Properties

To find references to an item, right-click the item and select Find All References, or press Shift+F12.

Check Syntax Errors in Your Code

If you leave out a ;, }, or ), the syntax error is marked with a red squiggly line in the editor.

The Problems view in the bottom pane also lists the syntax errors. Double-click the problem to go to the source file.
Problems view, showing a missing semicolon in an Apex class

View an Outline of Your Apex Class or Trigger

The Apex outline view shows the structure of the Apex class or trigger that’s open in the editor. For a list of the symbols in your file, press Cmd+Shift+O (macOS) or Ctrl+Shift+O (Windows or Linux). To jump to one of the symbols, select it in the list.
Outline view, showing the symbols in an Apex class

Enable Code Smartness for SObjects

To activate this extension’s code smartness features for standard and custom objects and their fields, including for custom fields on standard objects, press Cmd+Shift+P (macOS) or Ctrl+Shift+P (Windows or Linux), and then select SFDX: Refresh SObject Definitions from the command palette.

When you refresh your sObject definitions, VS Code uses your default org to generate faux Apex classes. These faux classes represent the standard and custom objects that the admin user has access to for your default scratch org, or the logged-in user of your sandbox or DE org. The classes are stored in a hidden directory on your local workstation. Don’t edit the faux classes! They are deleted and regenerated each time that you refresh your sObject definitions. To modify your sObjects, either modify the objects’ .object-meta.xml and .field-meta.xml files (and then run SFDX: Push Source to Default Scratch Org or SFDX: Deploy Source to Org), or make changes declaratively in your org (and then run SFDX: Pull Source from Default Scratch Org or SFDX: Retrieve Source from Org). Your user doesn’t automatically gain access to new custom objects, so be sure to assign new permissions to the user as necessary. To assign permissions from the command line, run sfdx force:user:permset:assign -n YourPermSetName.

After you add or edit standard or custom objects or their fields, be sure to rerun SFDX: Refresh SObject Definitions.

Monitor Apex Language Server Output

The Apex Language Server is an implementation of the Language Server Protocol 3.0 specification. The Language Server Protocol allows a tool (in this case, VS Code) to communicate with a language smartness provider (the server). VS Code uses the Apex Language Server to show outlines of Apex classes and triggers, code-completion suggestions, and syntactic errors. To see all diagnostic information from the Apex Language Server, select View > Output, then choose Apex Language Server from the dropdown menu. The diagnostic information gives you insights into the progress of the language server and shows the problems encountered.

Troubleshooting

Salesforce Extensions for VS Code functions properly only if the root directory of your open project contains an sfdx-project.json file.

If you’re not seeing the Apex completion suggestions that you expect, your Apex database might need to be rebuilt. Quit VS Code, and then delete the .sfdx/tools/apex.db file from your project. Then relaunch VS Code, and open an Apex class or trigger. The Apex database rebuilds within about 5 seconds (up to 30 seconds for very large code bases).

Bugs and Feedback

To report issues with Salesforce Extensions for VS Code, open a bug on GitHub. If you would like to suggest a feature, create a feature request on Github.

Resources


Currently, Visual Studio Code extensions are not signed or verified on the Microsoft Visual Studio Code Marketplace. Salesforce provides the Secure Hash Algorithm (SHA) of each extension that we publish. Consult Manually Verify the salesforcedx-vscode Extensions’ Authenticity to learn how to verify the extensions.