Skip to main content

(Devops) How to use Visual Studio Code IDE for deploying in Salesforce?

 

How to use VS Code IDE for deploying in Salesforce?


The Visual Studio Code IDE was introduced by Microsoft in 2015. One of the main advantages with Visual Studio Code IDE is its in-built debugger which makes the development code flow easily without requiring multiple clicks and maintains a single view with code and debugger. This also means that the bug-tracking and code run-throughs are a lot easier and faster.

With the above advantages of VS Code, many developers and Devops teams are adopting this tool for development and deployment of code in Salesforce. I am going to walkthrough the process of setting up VS Code for Salesforce development and deployment as shown below:


Step 1: Download and Install VS Code

To download visual studio code , open the link https://code.visualstudio.com/ and click on "Download" button to download a specific version to your system. For example Windows or Mac version based on your OS. Although there are insider builds and online builds, I would recommend you to install a stable version to avoid any IDE bugs. However, if you want to explore latest features of VS Code, feel free to download the insider bugs which showcase latest features which are currently being tested but not released yet.


Step 2 : Download and Install Salesforce extensions pack

After installing VS code, I would recommend you to install Salesforce CLI Pack before installing the Salesforce extensions. The Salesforce CLI (Command Line Interface) pack enables you to control the full application lifecycle of salesforce apps. Through the command line instructions, it is easy to create create or connect to different environments used for development, testing, staging and synchronise metadata, code between your orgs and a version control system such as GitHub/VS Code.

The Salesforce CLI could be downloaded from the link as shown below:
 CLI - https://developer.salesforce.com/tools/sfdxcli

  • Once installation is complete, to confirm that the latest version of CLI is installed, please run the following command from the command line prompt.
           sfdx update 

  • You should see the output for this command as: sfdx-cli: Updating CLI... 

Now, it is time to install Salesforce extensions pack for vs code. The salesforce extension pack provides deep integrations with Salesforce tooling throughout VS Code. This extension pack installs the essential Salesforce extensions all at once, saving time instead of selecting each individual extension to install.

With Salesforce extensions you can invoke Salesforce CLI from various methods such as VS Code menus, shortcut keys and right click context menus. New functionality shows up as you are working with VS Code such as:

  • Language services for Visualforce pages and Apex Classes
  • Language services for Lightening components (Aura and Lightening web components)
  • Integrations in the activity bar for Apex tests and Replay Debugger.

1. Once you launch Visual Studio Code, click on 'Extensions' from the left hand toolbar. 

2. Enter 'Salesforce Extension Pack' in the search field.

3. Click on 'Salesforce Extension Pack'

4. Click on "Install"

5. Close and relaunch the Visual Studio Code for extensions to work.


Step 3:  Connecting to Salesforce Org

As you have now installed Salesforce CLI and all the required extensions, you could go ahead to connect your Salesforce org with VS Code IDE. Use command Ctrl + Shift + P or go to View -> Command Palette. In the command palette type :Create Project with Manifest and press 'Enter' button on the first option as shown below:




Select 'Standard' and enter the name of the project. For example, 'MyFirstProject'. The project will be created and the menu will appear on the left hand side as shown below:



Once the project is created, we need authorize the salesforce org. In order to do this, click on Ctrl + Shift + P or go to View -> Command Palette. In the command palette type: Authorize an org and press 'Enter' button on the first option as shown below:



We now need to select the environment we want to authorize such as sandbox environment or production environment as shown below:



I have a ready sandbox environment which is a mirror image of production and once I select this environment, the vs code editor would prompt for Org alias name e.g. MyFirstProjectOrg (similar to the name of my project). After pressing Enter button, it will open my default browser prompting me to enter login details. After logging in with your credentials, the Salesforce CLI would request permissions to open your org. Once the Salesforce CLI is able to authorise your org, you would see the commands as shown below:


Step 4: 

Once your org is successfully authorised, you may want to get all the Apex classes, trigger and other required files into the IDE. In order to do this, open the package.xml  from the manifest subfolder as shown in the left panel.  Once you right click on the package.xml and select the option SFDX: Retrieve Source in Manifest from Org as shown below:


Step 5:

Once your org is authorised, you could proceed to create an Apex Class. Click on the Explorer in Visual Studio code to expand the force-app folder. Next click on the VSCODEQUICKSTART directory, click force-app folder to show the full list of folders. Under the force-app/main/default directory, you find the metadata included within project such as applications, aura, classes and many more.  

Open the command palette from View -> Command (Ctrl/Command + Shift + P), type SFDX: Create Apex Class. Type the class name as "AccountController".

Navigate to the folder force-app/main/default classes as the directory where you would want to add the folder "AccountController.cls" class. Now open the class in the editor and replace the default code with the following code:

Public with sharing class AccountController {

  public static List <Account> getallActiveAccounts() {

     return { SELECT Id.Name_Active_c from Accounts where Active_c = "Yes" };

   }

}

Run the above SOQL query in your org before deploying your org. We use the command palette to run this query and deploy this code in your org by typing SFDX: Execute SOQL  query with currently selected text and press Enter. 

Select REST API and press Enter. In order to deploy your org, open command prompt Command + Shift + P for Mac or Ctrl + Shift + P for Windows OS and type SFDX: Deploy Source to Org.  In the output tab of the integrated terminal, the command SFDX: Deploy Source to Org ...ended with exit code 0. This means that the deploy command ran successfully. 





You have now deployed your code into Salesforce using VS Code! 




Comments

Popular posts from this blog

How do Sales Engagement Platforms drive Organisation’s revenue?

How do Sales Engagement Platforms drive Organisation’s revenue? Increasingly Sales Engagement platforms are used by organizations to enrich their sales teams with relevant information to improve their performance and increase sales productivity. These software tools help sales teams improve productivity by automating, optimising and analyzing their sales teams outreach and communication efforts. They typically provide a suite of features designed to help sales reps increase their productivity, improve their communication with prospects and customers leading to close more deals. Some common features of sales engagement platforms include: Email automation — Sales engagement platforms allow users to create and send personalized email messages to prospects and customers at scale. This helps sales reps to save time and increase their email response rates. Call automation — Some sales engagement platforms such as Gong, Chorus.io offer the ability to automate outbound phone calls, allowing sa

(DevOps) How to select a relevant Application Lifecycle Management (ALM) Salesforce model for your organisation?

  How to select a relevant Application Lifecycle Management Salesforce Model for your organisation ? Salesforce provides many different development tools and process to help meet customer requirements and needs. As many companies use Salesforce and Application Lifecycle management (ALM) processes, Salesforce has introduced three different models to manage ALM process within the organisation as shown below: Change set development Org development Package development From the surface all the above three development models follow the same ALM process. However, the models differ in the way they allow changes to your org and how you manage these changes. Controlling change is a huge deal in software development, and you could choose the development model that best suits your organisation needs and requirements. Firstly, let us understand what is the meaning of ALM for an organisation. Application Lifecycle Management is an integrated system of people, tools and processes that supervise a sof

(Ops) Why are organisations adopting PRM in Salesforce?

  Why are organisations adopting PRM in Salesforce? In this article, we focus on what is Partner Relationship Management and why organisations are increasingly adopting PRM solutions. We also discuss advantages and disadvantages of using Salesforce PRM to collaborate with partners. What is Partner Relationship Management (PRM)? The Partner Relationship Management solutions developed in the last 10-15 years is a type of software used by companies to facilitate execution of Channel Sales .  Channel Sales is a simple sales strategy used by companies to leverage the help of third-party vendors to sell your products and services. Channel sales strategies are usually deployed as part of your business growth effort. Channel Sales can help business grow in three key ways: To reach new customers who don't buy directly from the vendor, preferring instead to buy from resellers or ISV's (Independent software vendors). To sell products through third-party market places and managed service p