What is LWC?
Lightning Web Components (LWC) is a modern web-based UI framework introduced by Salesforce. It is built using standard web technologies like JavaScript, HTML, and CSS, enabling developers to create efficient and scalable applications on the Salesforce platform.
Why Use LWC?
LWC provides several advantages over previous frameworks like Aura Components:
- Performance: LWC leverages native browser capabilities, making it faster.
- Standard Web Technologies: Uses modern JavaScript and web standards, reducing the learning curve.
- Better Security: Follows Salesforce Locker Service for secure coding practices.
- Ease of Maintenance: A more modular and reusable approach to UI development.
Setting Up the Development Environment
To start developing in LWC, follow these steps:
- Install Salesforce CLI – Required for Salesforce DX development.
- Set Up a Salesforce Developer Org or Sandbox
- Install VS Code and Salesforce Extension Pack
- Create a Salesforce DX Project:
sfdx force:project:create -n myLWCProject - Authorize Your Org:
sfdx force:auth:web:login -d -a myDevOrg - Create an LWC Component:
sfdx force:lightning:component:create -n HelloWorld -d force-app/main/default/lwc
LWC Component Structure
Each LWC component consists of four main files:
- HTML File (
.html) – Defines the component’s UI. - JavaScript File (
.js) – Implements the component’s logic. - Meta XML File (
.xml) – Configures component visibility and API access. - CSS File (
.css) (optional) – For styling the component.
Your First LWC Component: Hello World
Create a simple LWC component to display “Hello, World!”.
helloWorld.html
<template>
<h1>Hello, {greeting}!</h1>
</template>
helloWorld.js
import { LightningElement } from 'lwc';
export default class HelloWorld extends LightningElement {
greeting = 'World';
}
helloWorld.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"
fqn="HelloWorld">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Deploying and Using Your LWC Component
- Deploy your component:
sfdx force:source:push - Add it to a Lightning page via the Lightning App Builder.
- Save and activate to see “Hello, World!” on your Salesforce page.
Conclusion
Congratulations! 🎉 You have created your first LWC component. In the next post, we will explore LWC Component Structure & Lifecycle to understand how components interact with the Salesforce platform.
Stay tuned! 🚀

