Using VS Code IDE For Salesforce
In the previous part, we learned about How to configure VS Code for Salesforce. Here we will learn about using VS Code IDE for your Salesforce project.
Salesforce allows you to code directly from the browser or from their Developer Console (LWC not supported in dev console). Along with this, there was Eclipse IDE support as well which allowed doing the development from there. However, Salesforce doesn’t support Eclipse IDE anymore.
Development using VS Code IDE is really awesome and once you start using it you will know why 🙂
Let’s kickstart the journey of using VS Code IDE for Salesforce which is as follows:
1. Create A Project With Manifest:
In the VS Code editor enter Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows) to open the Command Palette. Enter SFDX: Create Project with Manifest in the command palette. ( You can just type Create and auto-suggest will show you the required command)
Select Standard.
Enter the name of the project and hit the enter key.
Please select the appropriate folder location on your local machine and save this project.
2. Authorize An Org:
Once you have created your project you are supposed to link your Salesforce org to this created project.
Open the command palette and enter SFDX: Authorize an Org (You can type Authorize and auto-suggest will show you the required command).
You can select the Project Default option if you are connecting a developer org or can pick Sandbox if you wanted to connect to a sandbox org.
Enter an alias for the org you are connecting to.
Now you will be redirected to a browser with the login page of Salesforce opened. Enter the username and password and click Log In to complete the authentication steps.
Once successfully logged in you can come back to the VS Code IDE as authentication is completed and you are all set to create your code components.
3. Retreive Source From The Org:
Using the manifest file you can pull the existing metadata locally.
Go to manifest > package.xml and right-click on it. Click on SFDX: Retrieve Source in Manifest from Org.
You can also open the command palette and enter the command SFDX: Retrieve Source in Manifest from Org
Please notice the pacakge.xml file. By default, it will pull all the members present in the org for the given types as it has <members>*</members>.
If you want only selected components then update the package.xml with the required members.
4. Creating Source:
Let’s create an Apex Class for this demo.
Open Comand Palette and Enter SFDX: Create Apex Class
Enter the name of the Apex Class.
Choose the default option and hit enter.
You are all set to write your code in the Apex Class.
Similarly, you can create Apex Trigger, Aura Component, etc by selecting the respective create commands.
5. Deploy Source To Org:
In the above point, we have created a new class but it is still not saved into your Salesforce org and is present locally.
Open the command palette and enter SFDX:Deploy This Source to Org
This will deploy this source in the org which you have connected to this project.
6. Delete Source From Org:
Let’s say you wanted to delete the Apex Class created in the above step.
Open the command palette and enter SFDX:Delete This from Project and Org
You can also right-click on the source file and click SFDX: Delete from Project and Org to delete it.
Thank you for visiting SalesforceBlue.com
If you have any queries feel free to write down a comment below 🙂