Authorize a Salesforce Org using VSCode
To start building custom LWC Components in Salesforce, you need to make sure to install Salesforce CLI and VSCode. Once you have done that, you will need to authorize a Salesforce Org using VSCode to be able to make changes to the Salesforce metadata using CLI Commands.
In this article, we are going to go through the steps of Authorizing your org and deploying changes to the connected Salesforce environment.
Create a Project in VSCode
Step 1: Create a Salesforce Project in your file location.
First, you need to create a project in VSCode. Open your VSCode and press Ctrl + Shift + P to open the command pallet where you can search for all the SFDX Commands.
Note: These commands are provided by the Salesforce Extension Pack and they run CLI commands in the backend, which you can verify in the VSCode console when you execute a command.
To create a Salesforce Project, you will need to search and select the below command.
SFDX: Create Project with Manifest

Step 2: Select the Project template.
Select the Standard template, which will create the complete folder structure and files which are required for a Salesforce project.

Step 3: Enter the name of the Project you are creating.
You can give it any logical name, this will be the name of the project folder, then press Enter.

Click on Create Project button

After clicking on the Create Project button, you can see all the folder structures and files created. Check the root folder name, it’s the same as the value you entered in Step 3 above. So make sure you choose a name that makes it meaningful for this project.

Now that our Project is created, it’s now time to connect it to our Salesforce Org and then continue our development/ deployment from VSCode.
Authorize a Salesforce Org
You need to authorize an Org before you can start making changes to it via VSCode.
Step 1: To authorize an org you need to press Ctrl + Shift + P to open the Command Pallet. Then search and select the below command.
SFDX: Authorize an Org

Next, you will be asked to select the type of the org you want to connect to. In my case, I am working on my Salesforce Dev org so I have selected Production. If you want to connect to a Sandbox you can select Sandbox or if you have a custom URL you can select Custom.

Step 2: Create an alias for the org Authorizing to.
In the next screen, you will be asked to create an alias for the org you are connecting to. Alias is a short name with which you can associate an authorized org, give it a meaningful name.
In future when you will be working with multiple orgs, you might have to authorize multiple of them in your VSCode so make sure the alias name is unique and meaningful.
As once an org is authorized it gets saved in the VSCode. With multiple authorized environments in place, you will have the option to switch and connect to any Salesforce environment.

Once you enter the alias name, you can see a status popup at the bottom of the screen.

Step 3: Single sign-on to your Salesforce org and Allow Access to VSCode.
A new window in your browser will open, asking you to enter the credentials and authorize the org to connect with VSCode.
Once you successfully login an Allow Access prompt box will show on the screen, click on the Allow button to proceed further.

Now, go back to your VSCode and you should see the Success message in the status popup(on the right) and the alias name(on the left) of the org you authorized.
Click on this alias name and you can see many options, explore these and let me know in the comment box below if you have any questions.

Closing Thoughts
Do let me know in the comment box below if this article helped you to authorize your VSCode with a Salesforce Environment. If you are still facing issues, make sure to post a comment below and I will give my best to respond to them and resolve any issues.
Share this article with your friends and also subscribe to my newsletter to get notified of any new articles getting published.
One Comment