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
  • Reterieve existing apex classes from sandbox into 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 *