Lesson 10 of 14 · All lessons

Section 4 · User Interface · 25% of exam

4.2 Lightning Web Components, Data Access, and Events

3 min read Updated Nov 16, 2026

Exam objective

Describe Lightning Web Components use cases and best practices, including the framework, benefits, and event communication; select components that meet a user-interface scenario.

Why use Lightning Web Components

Lightning Web Components (LWC) use standard HTML, CSS, and modern JavaScript concepts within the Salesforce component model. They are suited to reusable Lightning interfaces, custom interactions, and components placed on supported Salesforce pages or experiences. The framework provides lifecycle hooks, reactive properties, templates, events, and platform services. Reuse is valuable when a component owns one clear responsibility, such as showing an account's open cases or collecting a structured filter.

Start with standard Lightning components and platform record services before writing custom markup. A standard record form provides built-in behavior and accessibility; an LWC is justified when the experience needs a layout, interaction, or reusable behavior not supported by standard components. Keep data operations separate from presentation so the component can render state while a service or data adapter obtains it.

Reactive data with the wire service

The LWC wire service provisions data reactively. A component can use a wire adapter from Lightning Data Service or an Apex method. When a reactive parameter changes, the framework provisions new data and rerenders the component as appropriate. Wired Apex methods must be cacheable and read-only. For a user-controlled operation that changes records or must run at a specific moment, an imperative call can be a better fit. After a mutation, use the documented refresh or data-notification mechanism so the interface reflects the current record state.

Choose between UI API and Apex deliberately. UI API adapters are usually preferable for standard record data because they integrate with platform permissions and metadata. Apex can provide a custom result or coordinated transaction, but the component must handle loading, success, empty, and error states. Avoid issuing the same request in both connectedCallback and a wire without a reason; redundant requests create inconsistent UI and unnecessary load.

Communicate across components

Data and events flow along defined relationships. A parent can pass public properties down to a child, or call a child public method through its component reference. A child can dispatch a DOM event to notify its parent about a user action. The parent can listen and decide how to respond. For components that do not share a direct parent-child relationship, Lightning Message Service supports communication across supported component types and contexts.

A custom event should have a clear name and a small detail payload. By default, events do not need to be made public across the entire component tree. Setting bubbles and composed to true expands propagation and makes the event part of a wider API contract; use the narrowest propagation that works. A change in event configuration may affect consumers in pages that the component author does not control.

Accessibility and interface reliability

Use semantic elements, labels, keyboard-friendly controls, visible focus, and meaningful error messages. Do not communicate an error by color alone. A component should manage loading and empty states as well as successful results. If a user selects an account and then changes a filter, ensure the display reflects the new state and stale results are not presented as current. Separate component state from server response and handle asynchronous completion carefully.

In a scenario, identify where each component sits in the hierarchy. That determines whether properties, public methods, DOM events, or Lightning Message Service is the natural communication path.

Extra concept: events are public contracts

An event name, payload shape, and propagation behavior are part of how components integrate. Keep the contract stable, document the expected payload, and avoid leaking unnecessary record data in the event. A parent that receives an event should still validate any server operation it initiates.

Key takeaways

  • Prefer standard components and UI API when they satisfy the use case; build LWC for custom reusable behavior.
  • Use wire for reactive read operations and imperative Apex for explicitly initiated or mutating operations when appropriate.
  • Pass values down, dispatch events up, and use Lightning Message Service for supported loosely coupled communication. Official references:
  • Salesforce Certified Platform Developer Exam Guide: https://help.salesforce.com/s/articleView?id=005298965&language=en_US&type=1
  • Lightning Web Components Developer Guide: https://developer.salesforce.com/docs/platform/lwc/guide
  • Wire service: https://developer.salesforce.com/docs/platform/lwc/guide/data-wire-service.html
  • Communicate with events: https://developer.salesforce.com/docs/platform/lwc/guide/events.html
  • Event best practices: https://developer.salesforce.com/docs/platform/lwc/guide/events-best-practices.html
  • Lightning Message Service: https://developer.salesforce.com/docs/platform/lwc/guide/use-message-channel.html
  • Lightning Data Service: https://developer.salesforce.com/docs/platform/lwc/guide/data-ui-api.html

Check your knowledge

Answer exam-style User Interface questions with answers and explanations.

Practice User Interface
Finished this lesson? Mark it complete to track your progress.

Ready for the real exam?

Take the timed Salesforce Platform Developer simulator: same number of questions, same time limit.

Get Complete Access