INTRODUCTORY SERIES
Anatomy of Lightning Web Component
In the introductory blog post, we learnt about the ‘What-Why-How’ of a new paradigm of UI development in Salesforce called as Lightning Web Component (LWC) framework. It is next in the evolutionary phase after the Aura framework and Salesforce has made big bets on it by going open source. In this post, we are going…
Lightning Web Components – Introduction (In Pictures)
This blog is primarily intended to serve as a refresher and a quick primer to know and then speak about LWC to anyone (customers, partners, fellow developers and in community). I have always tried to conceive complex ideas and concepts with visualizations. It helps with the retention and gives you talking points to speak if…
We learnt the basics of lightning web components in an introductory two part series – Introduction to LWC and Anatomy of a web component. But before we start brewing some kickass web components, we need to prepare our kitchen and gather the apt utensils! In this blogpost, we are going to setup the development environment needed to create and deploy lightning web components for our Salesforce orgs.
However you might be wondering – “I never needed to setup anything while creating VF pages or even Aura components. I could simply create them in Developer Console. Why do I need it now ?”
Quick answer is – Because you cannot create lightning web components in Developer Console.
You cannot create lightning web components in Developer Console.
But this is also tied to the paradigm shift that has recently occurred in the Salesforce development lifecycle, weighing more on Source driven development against the yesteryear’s Org based development. This new methodology also called as ‘Salesforce DX’ consists of new tools that streamline the entire development life cycle. In this blogpost, we are going to look at the bare minimum tooling that is needed to ship your first lightning web component. So let’s start
Tools needed for development – Salesforce CLI, VS code and Org (scratch/Non scratch org)
1. Salesforce Command Line Interface
Salesforce CLI is a command-line-interface which can help you (and VS code!) talk with the Salesforce org in form of ?
YES ! “Commands” (What else ?)
It is a powerful tool which can help you create LWCs, Apex classes, deploying and retrieving the metadata to/from Salesforce, execute unit tests, create and install packages etc. As you would have guessed, there is not much you can do without Salesforce CLI. Download the CLI as per your OS with help from below links
| OS | Installation Link |
| macOS | https://sfdc.co/sfdx_cli_osx |
| Windows(32 Bit) | https://sfdc.co/sfdx_cli_win |
| Windows(64 Bit) | https://sfdc.co/sfdx_cli_win64 |
| Debian/Ubuntu(x64) | https://sfdc.co/sfdx_cli_linux |
| Debian/Ubuntu(x86) | https://sfdc.co/sfdx_cli_linux_x86 |
Once the CLI installer is downloaded, click on it and the installation commences. After the installation is completed you might need to set the path in your environment variables. To verify if CLI is ready to go just type the below command in terminal (macOS) or command-prompt (windows)
sfdx --version
You will see the CLI spitting out something like below
anandgupta@Anands-MBP Documents % sfdx --version
sfdx-cli/7.74.1-32db2396ed darwin-x64 node-v12.18.3
We are done with the first step of setting up our kitchen and not far from rolling hot components on the table! Let’s not stop. Next we will be setting up our IDE.
2. Visual Studio Code – Install Salesforce Extension packs, Setup linting
But wait! What’s an IDE ?
IDE stands for Integrated Development Environment. It is basically a Text Editor but for Coding and having superpowers like – Code completion, debugger, automation tools etc. It is your saucepan to write recipes. There are many IDEs which can be used to write code, but for Salesforce the official recommendation is to use Visual Studio Code.
So let’s start by Downloading and Installing Visual Studio Code
- Download and install the latest version of the Visual Studio Code as per the OS
- Launch Visual Studio Code

Because VS Code is a generic code editor which is also used for development of many other programming languages like Java, python etc, it needs a special Salesforce flavouring. That is brought using what are called as – Extension packs.
But there is not much to think here as there is only one extension pack which you need to download and it takes care of everything (One ring to rule em all!). Follow along
- Open Visual Code Editor
- Click on the ‘Extension Icon’ from the left pane
- Search for ‘Salesforce Extension Pack’ in the search bar (You will see something like below)

4. Click on the Salesforce Extension Pack and you will see the documentation of the extension with a green ‘Install’ button. Clicking it will start the installation. Once the installation is complete, you can start using it straightaway without closing or reloading the editor.
This extension pack also installs some additional needed packs for Salesforce development along with it. So there is no need to install these packs individually.
Things are looking great. But we need to worry about the cleanliness as well. We have a tool just for that purpose and it is called as ‘Linter’.
Linting finds errors in your code as you are typing it. Sweat more while your coding so that you can bleed less when compiling ! It consists of set of rules that run on your code based on defined patterns and practices. Salesforce Extension Pack by default installs ‘ESLint’ on your VSCode such that it runs everytime you work on a Lightning Web Component.
That completes our kitchen work!
3. Request a Salesforce Developer Edition Org and enable MyDomain
If you already have a Salesforce Developer Org, you can skip this step. To request one, sign up for a developer edition org using the below link below
Developer Edition Sign-up Form
Lightning web components can be created in both scratch and non scratch orgs. For simplicity of the topic, we are going to consider non-scratch orgs for discussion. Before you can start using Lightning web components, myDomain should be enabled in for any org.
Follow the steps here to enable myDomain for any org.
4. Create a project to start the development
A project holds the necessary structure of the Salesforce code base in the form of metadata files grouped in relevant folders stored locally. So let’s start to create a project which will house one of our metadata (lightning web component).
- Open Visual Studio Code.
- Press Command + Shift + P on macOS or Ctrl + Shift + P on Windows or Linux, then type create project. Select SFDX: Create Project, and press Enter.
- Choose a name (Leonardo ?), and press Enter.
- Choose a directory on your local machine where the project will be stored. Click Create Project.
Done! We next need to authorize our Salesforce Org and connect it to VS Code.
5. Authorize Development Environment in VS Code (Non Scratch Org methodology)
- Run SFDX : Authorize an Org command from the Command Palette in VS Code and select a login URL.
- Provide an alias(short name) for this org.
- Next a browser window will open –> Click on ‘Allow Access’ –> Return back to VS Code.
We are now ready to create our first Lightning Web Component
6. Create your first lightning web component
Just like how we used the Command Palette of VS code to create a project and authorize an org, we can use it again to create a lightning web component quickly
- Open Visual Studio Code.
- Press Command + Shift + P on macOS or Ctrl + Shift + P on Windows or Linux, then type Create and use the suggested ‘ SFDX : Create Lightning Web Component’
- Enter a suitable name.
This will create the necessary files (remember the anatomy of lwc) in the ‘lwc’ folder in your project. Fistbump ? (You have just created a lightning web component and it is ready to be deployed)
With this – We have now setup the complete tooling and path needed to develop Salesforce components (Apex Classes, VF pages, Aura components, Lightning Web Components, Apex Triggers etc) in our local system and deploy them to a Salesforce org.







