Lightning Web Components(LWC)
A modern Salesforce programming framework based on JavaScript, HTML, and Web Standards.
1) JavaScript Basics for LWC
Explanation:
LWC uses modern ES6 JavaScript.
Key Concepts:
- Variables:
let,const - Functions (normal + arrow)
- Classes & modules
- Promises & async/await
- Array functions (map, filter, reduce)
Example:
Why important?
All LWC components internally rely on JavaScript for logic.
2) HTML Templates
Explanation:
Every LWC has an HTML file that defines the UI layout.
Example LWC HTML:
Binding Types:
{propertyName}→ One-way data bindingonclick={handler}→ Event binding
3) LWC Lifecycle Hooks
Explanation:
Hooks are special functions that run during component load, update, or removal.
Most Used Hooks:
constructor()connectedCallback()renderedCallback()disconnectedCallback()
Example:
4) Lightning Data Service (LDS)
Explanation:
LDS lets you access Salesforce data without writing Apex.
Common Features:
- Retrieve record
- Create/Update record
- Delete record
Example Using LDS:
Purpose:
- No SOQL
- No Apex
- Secure and fast
5) Events in LWC
Explanation:
Events connect child → parent or communicate between components.
Types:
- Custom Events
- Lightning Message Service (LMS)
Example — Custom Event:
Child Component
Parent Component
6) Calling Apex from LWC
Explanation:
When LDS can’t handle complex logic, Apex is used.
Example:
Apex class
LWC JavaScript
7) Wire Service
Explanation:
@wire is used to read Salesforce data automatically and reactively.
Example:
Key Benefits:
- Auto-refresh
- Cache support
- Declarative
8) Navigation & UI Components
Explanation:
LWC has built-in components under the lightning namespace.
Example UI Components:
<lightning-input><lightning-card><lightning-button><lightning-datatable><lightning-record-form>
Navigation Example:
9) Deploying LWCs
Explanation:
LWCs are deployed using:
- Change Sets
- VS Code + Salesforce CLI
- DevOps Center
- Git-based CICD pipelines