Tuesday, May 28, 2019

Useful commands for SFDX in Visual Studio Code


  1. To pull changed source from the scratch org to the project: 
    • sfdx force:source:pull
  2. To pull source to the project if a conflict has been detected: 
    • sfdx force:source:pull --forceoverwrite
  3. To push changed source to a scratch org that’s not the default, you can indicate it by its username or alias:
    • sfdx force:source:push --targetusername test-b4agup43oxmu@example.com
    • sfdx force:source:push -u test-b4agup43oxmu@example.com
    • sfdx force:source:push -u MyGroovyScratchOrg

sfdx force:mdapi:retrieve giving “UNSUPPORTED_API_VERSION: Invalid Api version specified on URL.”

In CLI terminal, sfdx force --version and sfdx plugins revealed to me that even if my VSCode extensions are v44, and my CLI version is sfdx-cli/6.44.0-dead729fb5 (windows-x64) node-v8.9.4... well, apparently sfdx itself (which I thought was an abstraction) has a version #, and it was 45.
Solution is to manually override the API version used by your project
After moving into a project folder, specify a version override with the following command:
sfdx force:config:set apiVersion=44.0 This will allow you to use the newer 45.0 features in a LWC project, whilst still being able to work in a 44.0 org without any errors.
Make sure that, if you're playing with an advanced version of the API, that you keep the salesforcedx@pre-release plugin installed until it is upgraded to the latest release.

Setup Visual Studio Code(VSC) for Salesforce Development without Scratch Org

This is a step to step guide to setup Visual Studio Code for salesforce development without using Dev-Hub and Scratch Orgs, you can now use vs code for your Dev Org and Sandboxes just like any other IDE, also this will allow you to push your manifest at many org at once and even sync it with your Code Repository.



1. Install Salesforce CLI from this link https://developer.salesforce.com/tools/sfdxcli, if already installed make sure you have the latest version.
2. Download and Install Salesforce VsCode from here https://code.visualstudio.com/, if already installed make sure you have the latest version.
3. Install “Salesforce Extension Pack” from Extensions Marketplace in VS Code.

4. In the Terminal window, run the following command,
sfdx plugins:install salesforcedx@pre-release
If the terminal is not visible on UI then go to Menu->View->Terminal
5. Create a Project
  • Press “CTRL+SHIFT+P” then select  “SFDX: Create Project with Manifest
VS Create Project with manfest
  • Then enter your Project Name and select a folder where you want to keep all your local copy of Manifest and ProjectFiles.
Enter project name
6. Authorize your Dev Org or Sandbox
  • Press “CTRL+SHIFT+P” then select  “SFDX: Authorize an Org
Authorize Dev Org7. Select Org Type
Enter Org Type
After Successful login, you can close the browser and you can notice that few files and folder are now displayed in the left sidebar.
8. Retrieve Metadata
  • Now we will be retrieving all the necessary manifest to make changes, for that expand the manifest folder and open package.xml in the editor. (If you are working on fresh org you can skip this step)
  • Edit package XML to retrieve desired components from the authorized org.
  • After that right click on package.xml either in Explorer or in the Editor Window and click on SFDX: Retrieve Source in Manifest from Org
Retrieve Metadata
After the retrieval process is completed you can see your metadata in force-app folder in the explorer.
9. Deploy Metadata
  • After you are done with changes in your Metadata, just right click on that file and click on SFDX: Deploy This Source to Org, it will deploy your changes to Authorized org and remember that the source you deploy overwrites the corresponding metadata in your Org
Deploy Metadata
Good luck with the development in VS Code and say goodbye to other IDEs.
Some useful links:
1. Salesforce CLI Documentation