Best Visual Studio Code (VS Code) Extensions for Salesforce Developers [UPDATED – 20/07/2019]

  1. Alignment
    Align code based on special characters (Alt + =).
  2. Salesforce Extension Pack
    Collection of Salesforce official extensions.
  3. Apex Javadoc
    Add Javadoc comment (/** then press tab).
  4. Apex PMD
    Apex static code analysis.
  5. Auto Close Tag
    Automatically add HTML/XML close tag (Add following config to  activate).
    "auto-close-tag.activationOnLanguage": ["*"]
  6. Auto Rename Tag
    Automatically rename paired HTML/XML tag (Add following config  to  activate).
    "auto-rename-tag.activationOnLanguage": ["*"]
  7. Beautify
    Beautify javascript, JSON, CSS, Sass, and HTML (F1).
  8. Better Comments
    Style the comments based on category.
    Bookmark lines in code (Right Click > Bookmarks: Toggle)
  10. Bracket Pair Colorizer
    Colorize matching brackets.
  11. change-case
    Change case of selected text.
  12. Code Spell Checker
    Spell checking on code.
  13. Color Highlight
    Display colors found in code.
  14. Comment Anchors
    Place anchors within comments and navigate easily.
    ANCHOR - Used to indicate a section in your file
    TODO - An item that is awaiting competion
    FIXME - An item that requires a bugfix
    STUB - Used for generated default snippets
    NOTE - An important note for a specific code section
    REVIEW - An item that needs additional review
    SECTION - Used to define a region (See 'Hierarchical anchors')
  15. CSS Peek
    Allow peeking to css ID and class strings as definitions.
  16. ESLint
    Integrates ESLint JavaScript. Follow these steps after installing the extension.
    In terminal run following commands.
    • npm install -g eslint
    • eslint –init 
  17. Git History
    View git log, file history, compare branches or commits
  18. gitignore
    Language support for .gitignore files
  19. GitLens — Git supercharged
    Adds additional Git capabilities into VS Code.
  20. Indenticator
    Visually highlights the current indent depth.
  21. JavaScript Booster
    Adds extra functionalities for JS files.
  22. Nest Comments
    Toggle nested comments
  23. Partial Diff
    Compare (diff) text selections within a file, across files, or to the clipboard
  24. Prettier – Code formatter
    Code formatter (Ctrl + Shift + P). Follow steps below for config.
    • If you don’t already have a package.json in your project, run: npm init(You can accept all the defaults).
    • Install Prettier by running: npm install –save-dev –save-exact prettier.
    • Create a Prettier configuration file called .prettierrc, in the root of your project, with the following content.
        "trailingComma": "none",
        "overrides": [
            "files": "**/lwc/**/*.html",
            "options": { "parser": "lwc" }
            "files": "*.{cmp,page,component}",
            "options": { "parser": "html" }
      Finally install extension.
  25. Project Manager
    Switch between different projects.
  26. Remove empty lines
    Removes empty lines from selected text.
  27. Rewrap
    Re-wraps comments and other text to a given line length.
  28. Salesforce Documenter
    Automated Code Documentation Generation for Salesforce
  29. Salesforce Lightning Component Snippets
    Code snippets for Lightning.
    Trigger Type Example
    l: Lightning l:pill, l:layoutItem, l:verticalNavigationSection…
    a: Aura a:if, a:iteration, a:attribute…
    i: Interface i:hasRecordId, i:appHostable, i:hasSObjectName…
    h: Handler h:init
  30. Salesforce Package.xml Generator Extension for VS Code
    Extension for generating Package.xml
  31. SalesforceDX Code Companion
    An extension that works alongside the Salesforce Extensions. After installing run following command to install required sfdx plugin
    sfdx plugins:install mo-dx-plugin
  32. Settings Sync
    Synchronize/Backup settings and other VS code configurations.
  33. Split Lines
    Splitting Lines With String Literals.
  34. Trailing Spaces
    Highlight trailing spaces in code.
  35. Turbo Console Log
    Automatically create meaningful console.log() messages for selected variable ( ctrl + alt + L)
  36. Uncrustify
    Code formatter for Apex. (add following config to enable)
    “uncrustify.langOverrides”: {
        “apex”: “JAVA”
  37. Visual Studio IntelliCode
    AI-assisted development features
  38. VTools
    Autohide sidebar and bottom bar when click outside.
  39. XML
    XML Language Support (support for -meta.xml or package.xml)

Salesforce CLI

Salesforce CLI

What is it ?

The Salesforce CLI is command line interface for Salesforce comes under Salesforce DX tools. An introduction to Salesforce DX is given here.

What it can do ?

Salesforce CLI can perform various tasks including;

  • Creating APEX classes, running tests and view test results.
  • Import CSV files with the Bulk API.
  • Create and test Lightning component bundles.
  • View org’s limits.
  • Create and delete scratch orgs.
  • Manage users.
  • Create and manage packages (1st and 2nd generation)
  • View the metadata.
  • Create Visualforce pages and components.
  • Push and pull source to and from scratch orgs.

How to install ?

Salesforce CLI can be downloaded from here. For Windows, download and run the installer. Make sure Git is installed and PATH is set properly. You can verify installation by typing ‘sfdx –version’ in command prompt.

If you are using Windows 10, Windows Subsystem for Linux (WSL) allows you to run native Linux command-line tools on Windows 10 alongside your traditional Windows desktop. Detailed instructions can be found here.

If you have already installed, run sfdx update to get the latest version of Salesforce CLI. It is recommended to exclude installation directory (%LOCALAPPDATA%\sfdx) from antivirus software since it could slow down CLI.

Installed, Now what ?

Next step is to authorize your Salesforce org. To do that type “sfdx force:auth:web:login --setalias your-alias --instanceurl” in the command prompt (CMD). This will opens up Salesforce login page on web browser. Then enter login details to authorize. Once you done that cmd will display following message.

Successfully authorized with org ID 00D700F0050wfmJUAQ
You may now close the browser

By typing sfdx force:org:list you will able to see orgs which are already connected. To remove a connection,  navigate into %USERPROFILE%/.sfdx (C:\Users\USERNAME.sfdx) and delete file. (In linux, it will be in cd ~/.sfdx)

How to Create a Salesforce DX Project from Existing Source ?

If you have existing source and needs to convert it to Salesforce DX format, follow these steps.

  1. Create a Salesforce DX project.
    sfdx force:project:create --projectname mywork
  2. Create a directory to retrieve metadata.
    mkdir mdapipkg
  3. Use following commands to retrieve metadata.
    Format of Current Source Command
    Your source already defined as a managed package in your packaging org. sfdx force:mdapi:retrieve -s -r ./mdapipkg -u <username> -p <package name>
    You have a package.xml file that defines your unpackaged source. sfdx force:mdapi:retrieve -r ./mdapipkg -u <username> -k ./package.xml
    You don’t have your source defined in a package.
    1. Open the sandbox org that contains your metadata.
      sfdx force:org:open -u <username> --path one/
      You can use the sandbox username or an alias.
    2. Open All Setup.
    3. Open Package Manager.
    4. Create a package with the name of your application.
    5. Add the metadata source to the package.
    6. In your Salesforce DX project, create a folder for the MDAPI retrieve, for example, mdapipkg.
    7. Retrieve the metadata.
      sfdx force:mdapi:retrieve -s -r ./mdapipkg -u <username> -p <package name>
  4. While you in root directory, run unzip ./mdapipkg/ -d ./mdapipkg/. Please not that this will not work on windows command prompt and you will have to manually extract
  5. Change directory to project root and run following command to convert metadata into Salesforce DX project format.
    sfdx force:mdapi:convert -r ../mdapipkg

How to create a scratch org ?

  1. Enable Dev Hub by following these steps. Please note that this feature is only available on production orgs (Enterprise and Unlimited). But you can register for a 30-day trial org from here.
  2. Set authenticated org as the default Dev Hub org for scratch org creation.
    sfdx force:auth:web:login --setdefaultdevhubusername
  3. Create scratch org definition file. Sample format can be found here.
  4. Run following command to a create scratch org.
    sfdx force:org:create -f demo-scratch-def.json -a DemoScratchOrg (note down the username).
  5. By executing sfdx force:org:open -u <username/alias> will open up scratch org on the browser.

Scratch Org Limits ?

By default, Salesforce deletes scratch orgs and their associated ActiveScratchOrg records from your Dev Hub org when a scratch org expires. A scratch org expires in 7 days unless you set a duration when you create it.

Scratch orgs have these storage limits:

  • 200 MB for data
  • 50 MB for files

How to create an apex class ?

Navigate to classes directory in Salesforce DX project and run sfdx force:apex:class:create -n myclassname. Simlarly you can use force:apex:trigger:create, force:visualforce:page:create or force:visualforce:component:create. A complete list of Salesforce CLI commands can be found here.

How to  push source to the Scratch Org ?

After changing the source, you can sync the changes to your scratch org by pushing the changed source to it. Initially it will push all metadata into scratch org and then it will start tracking code changes. – sfdx force:source:push

You can use sfdx force:source:status to track changes in the source.

How to pull changes from Scratch Org to Project?

To pull changed source from the scratch org to the project:

sfdx force:source:pull

How to create a Scratch Org user ?

Use the force:user:create command to create a user. Specify the --setalias parameter to assign a simple name to the user that you can reference in later CLI commands.

sfdx force:user:list will display list of users and sfdx force:user:display -u will display user details including password.

How to run Apex tests ?

sfdx force:apex:test:run

How to deploy changes into Dev Hub ?

First step to deploy is converting Salesforce DX project into metadata format. To do that, run sfdx force:source:convert. Then execute sfdx force:mdapi:deploy -d metadataPackage_XXX to deploy. sfdx force:mdapi:deploy:report will display status of an asynchronous metadata deployment.