How to use visual studio code for Salesforce?

Lets learn how to create Salesforce project in visual studio code editor

  • Install sfdx-cli on your pc by typing command in terminal > npm install -g sfdx-cli
  • Verify installation is complete > sfdx -version
  • Install the Salesforce Extension Pack, inside vscode > extensions > Salesforce Extension Pack
    vscode salesforce extension
  • Create sfdx project in vscode
    • press cmd+shift+p inside vscode
    • select SFDX: Create Project
    • Enter name and press enter
    • Search project-scratch-def.json file
    • Edit orgName
      Vscode json for salesforce
  • Connect VS code to salesforce org
    • press cmd+shift+p inside vscode
    • Type SFDX: Authorize an Org
    • Press enter (accept default URL link)
    • Enter alias as vscodeIntegration
    • Grant access, through login page for salesforce sandbox
      vscode org access
    • Above vscode screenshot shows that integration is succesfull
  • Create salesforce code in VS Code
    • Create apex class
      • Right click on force-app > classes and select apex class
        create apex class in vscode
      • Enter name of class say AccountService > press enter
      • Replace newly created .cls code with
        public with sharing class AccountService {     public static List<Account> AccountService() {         List<Account> acct =  [SELECT Name FROM Account Limit 4];         return acct;     } } 
  • Deploy code to salesforce sandbox
    • Right click the classes folder and select deploy to org option
  • Verify its deployed by checking in sandbox > setup > devloper console> file > open > classes > AccountService
  • Create sfdx project in vscode with Manifest Settings 
    • Advantage, this gives better control what all the files that you want to retrieve from Org, which is managed by manifest.xml
    • press cmd+shift+p inside vscode
    • select SFDX: Create Project with Manifest
    • select standard project template
    • Enter name and press enter 
    • Follow the above steps to connect to Org
  • Retrieve code from source Org
    • After org connection is successful 
    • Right click on package.xml file and retrieve from Orgmanifestfile
    • Below command can also be used to retrieve from Org, in terminal of  VS Code > sfdx force:source:retrieve –metadata ApexClass:classnameretrieve existing classes in vscode


Leave a Reply

Your email address will not be published. Required fields are marked *