Best Visual Studio Code (VS Code) Extensions for Salesforce Developers

  1. Alignment
  2. Salesforce Extension Pack
  3. Apex Javadoc
  4. Apex PMD
  5. Appirio’s Salesforce Extension Pack
  6. Auto Close Tag
  7. Auto Rename Tag
  8. Beautify
  9. Better Comments
  11. Bracket Pair Colorizer
  12. change-case
  13. Code Runner
  14. Code Spell Checker
  15. Color Highlight
  16. Comment Anchors
  17. Comment Snippets
  18. CSS Peek
  19. ESLint
  20. gitignore
  21. GitLens — Git supercharged
  22. HTML Snippets
  23. Indenticator
  24. IntelliSense for CSS class names in HTML
  25. JavaScript (ES6) code snippets
  26. JavaScript Booster
  27. Nest Comments
  28. Partial Diff
  29. Prettier – Code formatter
  30. Project Manager
  31. Remove empty lines
  32. Rewrap
  33. Salesforce Diff
  34. Salesforce Documenter
  35. Salesforce Language Support
  36. Salesforce Lightning Component Snippets
  37. Salesforce Package.xml Generator Extension for VS Code
  38. SalesforceDX Code Companion
  39. Settings Sync
  40. Simple Search
  41. Smart Column Indenter
  42. Split Lines
  43. Trailing Spaces
  44. Turbo Console Log
  45. Uncrustify
  46. Visual Studio IntelliCode
  47. VSCode Apex PMD
  48. VTools
  49. XML Tools
  50. Git History

Testing Salesforce REST APIs using Postman

What is Postman ?

Postman is a REST client for testing, debugging, monitoring and documenting APIs.

Is it free ?

There is a free version available with limited features and functionalities.

Compare pricing and versions here –

Setting up

Download and install Postman. When you run Postman for the first time, it will ask for an account, which can be created for free.

Postman is a powerful utility which consists of many different functionalities, but this article will describe only basic features.

Creating workspace

Workspace is a view for collections, environments, monitors … etc. They can be created for organising APIs of different projects or clients. There are two main types of workspaces available. Team workspaces can be shared with others, while Personal workspaces are visible only to you.

  1. Click the workspace drop down menu in the header bar. 
  2. Click the Create New link.
  3. Determine whether you’d like to create a personal or team workspace.
  4. If you creating Team workspace, you can add members by entering their email address or username of existing users. A personal workspace will be used in this tutorial. 

Creating collection

A collection is a logical grouping for requests. Within a collection, you can create folders to have sub-groupings.

  1. In the sidebar, select “Collections” and click the “Collections” tab.
  2. Click “+ New Collection” link to create a collection.

Other functionalities of using collections are described here.

Setting up environments

The environments are useful when you have to test endpoints in multiple Sandboxes/Orgs. It can hold key-value pairs, which can be utilize to hold different login credentials. By using environments, you don’t have to duplicate same endpoint to call against different sandboxes.

  1. Manage Environments icon
  2. Click Add button
  3. Insert variables as given in table below.
    Variable Initial Value Current Value
  4. Next click “Persit All”
  5. Finally click “Add” and Select the environment you created from dropdown in right side corner.
  6. Similarly, you can add other orgs/sandboxes as environments.

Setting up authentication

Calling Salesforce REST API requires valid Oauth 2.0 token. Using Postman’s authentication it can be easily generated.

  1. Right Click on the Collection you created in previous step (or click View more actions icon) and click “Edit”.
  2. Goto “Authentication” tab.
  3. Select Type as “Oauth 2.0” and Add auth data to as “Request Headers”.
  4. Click “Get New Access Token” button.
  5. Enter any name for token. Eg : Salesforce Token and fill the form as below.
    Grant Type Password Credentials
    Access Token URL
    Username {{username}}
    Password {{password}}
    Client ID {{client_id}}
    Client Secret {{client_secret}}
    Client Authentication Send client credentials in body
  6. For Sandboxes use token URL as below.
  7. Click Get New Access Token, then it will generate new token.
  8. Next click “Use Token” button.
  9. Finally click “Update” button.

Calling REST API

  1. Right click on “Collection” and click “Add Request”.
  2. Enter a “Request name” and “Description”.
  3. Click “Save to Collection” button.
  4. Select the method (eg: GET) and enter endpoint URL after replacing base url with {{base_url}
  5. Finally hit “Send” button to execute.

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.