LWC Guide

Page 1 of 10

Salesforce Lightning Web Components from Scratch: A Concise, Rigorous Learning Guide

Executive summary

Lightning Web Components, or LWC, is Salesforce’s standards-oriented UI programming model for building reusable components with JavaScript, HTML, CSS, Web Components concepts, Salesforce metadata, and Salesforce data services. Salesforce recommends the Salesforce DX workflow—Salesforce CLI, a DX project, VS Code with the Salesforce Extension Pack, and a scratch org or sandbox—for the most integrated development experience. [1]

The fastest route to productive LWC development is not to memorize every decorator or base component. It is to learn the architecture in this order:

JavaScript and Web Components fundamentals → LWC component model → reactivity and data flow → composition and events → LDS/wire → Apex → forms/navigation → testing → security/performance/deployment.

The most important architectural rule is:

Prefer declarative, platform-managed mechanisms before writing custom code.

For Salesforce data, this translates into the following decision sequence:

Lightning base record components → Lightning Data Service/UI API wire adapters → imperative UI API functions → Apex only when Salesforce data services cannot satisfy the requirement. Salesforce explicitly recommends LDS where possible because it handles caching and security and keeps record data synchronized; Apex-returned data is not automatically managed by LDS. [2]

For component communication, the central mental model is:

Properties down, events up.

A parent passes values to a child through public @api properties; a child communicates changes upward with DOM/custom events. Public methods decorated with @api are appropriate when a parent must explicitly command a child to perform an operation. Salesforce recommends the least permissive event propagation that meets the requirement. [3]

For reactivity, modern LWC fields are reactive without @track; @track is primarily relevant when you intentionally need observation of mutations inside plain objects or arrays. In most application code, immutable-style reassignment such as { ...obj } or [...items] is easier to reason about and usually preferable. [4]

For data retrieval, the distinction between @wire and imperative calls is fundamental:

Question

Prefer

Should data automatically refresh when a reactive parameter changes?

@wire

Is this a read operation naturally managed by LDS/UI API?

LDS wire adapter

Must the operation happen only after a user action?

Imperative call

Does the Apex method perform DML?

Imperative Apex

Do you require custom SOQL, aggregation, transactions, unsupported APIs, or server-side business logic?

Apex

Can a base record form solve the problem?

Use the base component instead

The wire service provisions a reactive stream and is particularly suitable for reads. Imperative Apex gives the developer explicit control and is required for non-cacheable Apex operations such as DML. [5]

For security, assume client-side code is never a security boundary. Prefer LDS/UI API because Salesforce handles sharing, CRUD, and FLS. When Apex is required, make security explicit: use an appropriate sharing declaration and enforce object/field permissions with user-mode operations or Security.stripInaccessible() as required by the use case. In current API version 67.0, Apex security defaults have evolved, which makes explicit access-mode declarations particularly valuable for code that must remain understandable across API versions. [6]

Lightning Web Security is now the modern client-side isolation architecture; new orgs have LWS enabled by default, while Lightning Locker remains relevant for older configurations and some specialized containers. LWS uses JavaScript sandboxes and standards-oriented mechanisms rather than Locker's secure wrappers. [7]

A developer who is already comfortable with JavaScript and Salesforce can reasonably reach working LWC proficiency in roughly 25–35 focused hours and production-oriented competence after approximately 40–55 hours plus project experience. These are planning estimates for this guide rather than Salesforce estimates. Salesforce's current Build Lightning Web Components Trail itself contains roughly 11 hours of guided material, so hands-on repetition beyond Trailhead is essential. [8]

Foundations and development setup

Prerequisites

You should already understand modern JavaScript basics—classes, modules, destructuring, arrays, promises, async/await, events, object spread, and standard HTML/CSS. Salesforce's own learning materials expect familiarity with JavaScript/web standards and Salesforce DX fundamentals. [9]

For development, install:

Tool

Purpose

Salesforce CLI (sf)

Authenticate orgs, create projects/orgs/components, deploy/retrieve metadata

VS Code

Recommended editor

Salesforce Extension Pack

Salesforce metadata, Apex and LWC tooling

Node.js/npm

Jest, linting, supporting JavaScript tooling

Git

Version-controlled source

Salesforce org

Runtime environment

Salesforce recommends VS Code with its Salesforce extensions, although another editor can be used. Lightning web components cannot be developed directly in the Salesforce Developer Console. [10]