Lightning Web Components(LWC) is an exciting new technology launched in the Salesforce ecosystem not too long ago. Learning Lightning Web Components as a Salesforce admin has its own advantages. A few of them are:

  1. Have the ability to work with a developer as and when required.
  2. Can relate to what appears on the web page and provide constructive suggestions.
  3. Switch to a developer role if interested/needed.
  4. Can contribute to overall performance and add value to the project. 

What are Lightning Web Components?

Lightning Web Components is a new programming model for building lightning components. It is based on the latest web standards and ES6(ECMAScript). LWC makes use of HTML, CSS, and Javascript. It uses the core concepts of web standards; the security, lightning data service, and base lightning components are all taken care of by the browser, all thanks to these web standards.

Consider a scenario where you want a login and sign-up page for your customers to create an account and log in to see and buy the products from your website, that time; you can use Lightning Web components to create it. You can also make the look and feel of the website more interactive.

Benefits of Lightning Web Components

  1. Fast and Lightweight framework
  2. Offer enhanced security.
  3. Better testing since the Jest testing framework is used that helps to catch bugs at an early stage.
  4. Interoperability with lightning Aura components.
  5. Lightweight framework since we are using fewer tasks.

Let’s create a Lightning Web Component in Visual Studio Code

Step 1: Create a new project

  1. Open Visual Studio code and open the command palette by pressing Cmd+Shift+P for Mac or Ctrl+Shift+P for Windows.
  2. Make sure the new prompt starts with >.
  3. Search for SFDX: Create project and press Enter.
  4. Select the Standard Project template(default) and press Enter.
  5. Enter your Project name and press Enter.
  6. Select the location for the new project and click Create project.

Step 2: Authorize your Salesforce org

  1. Open the command palette by pressing Cmd+Shift+P for Mac or Ctrl+Shift+P for Windows.
  2. Type SFDX.
  3. Search for SFDX: Authorize an org and press Enter. It will open the browser and ask you to verify the credentials for your org where you want to build the LWC.

Step 3: Create a Lightning web component

  1. Open the command palette by pressing Cmd+Shift+P for Mac or Ctrl+Shift+P for Windows.
  2. Type SFDX.
  3. Search for SFDX: Create Lightning Web Component, give the component name, and press Enter.
  4. Now you will see three files created: the .html, .js, and .xml files. 

This is how the folder will look like:

Sample code for creating your first Lightning Web Component, just click on the file names to open the file to edit and copy & paste the following code to the corresponding files and save the files.

.html file code:

        <div class="slds-var-m-around_medium">
  • Line 2: Used a lightning-card to create a small card that can be used on a web page.
  • Line 4: Binding the property ‘greeting’ created in the JS file.

.js file code

import { LightningElement } from 'lwc';
export default class HelloSalesforceAdmins extends LightningElement 
    greeting='Hello Salesforce Admins!'
  • Line 1: Importing the LightningElement from the lwc package to provide our element with the lightning capacity.
  • Line 2: Extending the Lightning element to our element.
  • Line 4: Creating a property named ‘greeting’ and assigning it a value.

.XML file code

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">
  • Line 4: Exposing the Lightning web component to use an in-app page, record page, etc
  • Line 6: We are exposing the component to the lightning app home page to use it on that page.

Step 4: Deploy the source to your org

  1. Right-click on the component we just created and choose ‘SFDX: Deploy source to org‘.
  2. It will show you a message ‘SFDX: Deploy Source to Org successfully ran‘.

If the command ran successfully, a Deployed Source message lists the three files that are uploaded to the org can be seen in the Output tab of the terminal.

Step 5: Add Component to the App in Lightning Experience

  1. In Visual Studio Code, open the Command Palette by pressing Cmd+Shift+P for mac or Ctrl+Shift+P for windows.
  2. Type SFDX.
  3. Select SFDX:Open default org, (it will open your org in separate browser you authorized in step 2).
  4. From App Launcher, find and select Service app (or any other app you want to add the LWC).
  5. Click on gear icon and select Edit Page.
  6. Drag the ‘helloSalesforceAdmins’ Lightning web component from the left pane custom area of the Lightning Components list to the the Page Canvas.
  7. Click Save and Activation.
  8. Click Assign as Org Default and Save.
  9. Click arrow to return to the page.

 All set, new LWC will looks like below on the Service app page.

I hope you find this article helpful. I would love to hear from you! Share your tips in the comments!

Join our newsletter.

No spam, just learning!

Continue Reading

Get a free consultation.

Call us today at (469) 790-0063

Schedule a Consultation

Leave a Reply