Learner's Byte logo goes here
+
Oscar IT Solutions logo goes here

"Screen user ke kaam ka ho, developer ke shauk ka nahi."

"Build the screen for the user's work, not the developer's hobby." Components exist to make one job faster and safer.

  • Do we need a component?
  • Where does the data come from?
  • @api or event?
  • How do I call Apex?
  • Where does it appear?

Step 5, Part B: Lightning Web Components

Lightning Web Components (LWC) are Salesforce's modern way to build custom user interfaces, using standard HTML and JavaScript. You will build the booking panel that calls Part A's booking transaction, and a claim tracker for Suraksha.

You need
Part A, with BookingService in Org C and ClaimSettlementService in Org D
You will build
Four components: a customer card, a booking panel with a child checklist, and a claim tracker
Suggested time
4 live sessions of 90 minutes, plus about 10 hours of practice
AI skills used
Coding and Automation, Content Creation

You are hereSteps 1-4 Requirements and configurationSteps 5-9 DevelopmentSteps 10-11 Test and deploySteps 12-15 Rollout

Hook: seven clicks, three screens, one mistake

To book a car with standard pages, Arjun opened the opportunity, then the quote, then created an order, added products, changed the order status, went back to change the stage, and created a task. Seven clicks across three screens.

On a busy Saturday he forgot to change the stage. The deal stayed in Negotiation, the forecast was wrong, and delivery wasn't told.

The fix is one panel on the opportunity: three fields, a checklist, and one button that calls the booking transaction from Part A. Everything happens together, or nothing does.

Byte This: A good component turns a process people forget into a button they can't get wrong.

By the end of this workbook, you will be able to

  • Decide when a custom component is worth building.
  • Create a component's HTML, JavaScript and configuration files, and deploy it.
  • Use @api, reactive properties, getters and template directives.
  • Read and write data with base components, Lightning Data Service, and Apex.
  • Make components talk: properties, events, Lightning Message Service, navigation and toasts.
  • Place components on record pages, quick actions, flows and sites.

Concept: when to build a component

LWC, Aura and Visualforce

Our method's original Step 5 said "Visualforce and Apex". Today, build new screens in LWC, and learn to read Visualforce and Aura for older projects you'll maintain.

Anatomy of a component

A component is a folder with the same name as the component, holding these files.

The smallest useful component

customerCard.html
customerCard.js
customerCard.js-meta.xml

The building blocks

Template directives

Naming catches everyone once: the folder is camelCase, such as bookingChecklist. In another component's HTML you write it in kebab-case with the c- namespace: <c-booking-checklist>.

Working with data

Choose the simplest option that does the job. Each one down the ladder gives more control, and more code to own.

@wire or imperative?

Wire versus imperative, side by side

Try it: which data approach?

Components talking to each other

Lightning Message Service: publish and subscribe

Try it: which way should they talk?

Lifecycle, styling and placement

Lifecycle hooks

Styling

  • Use base components like lightning-card, lightning-input and lightning-button. They look right, are accessible, and update with Salesforce.
  • Use SLDS utility classes for spacing and text, such as slds-p-horizontal_medium and slds-text-heading_small.
  • A component's CSS file only affects that component, because of the shadow DOM.
  • Components run under Salesforce's client-side security, Lightning Web Security in current orgs, which keeps components from interfering with each other.

Where a component can appear

Demo: Kaveri booking panel

A parent component, bookingPanel, on the Opportunity page, with a child, bookingChecklist. It calls BookingService from Part A.

Try it first: a live preview

This preview behaves like the real component. The event log shows what happens inside: properties, events and the Apex call.

Confirm Booking

Priya: Ranger ZX

Customer: Priya Sharma

Stage: Negotiation

Deal value: ₹15,90,000

Before you confirm (child: c-booking-checklist)

Event log

The child: bookingChecklist

bookingChecklist.html
bookingChecklist.js
bookingChecklist.js-meta.xml

The parent: bookingPanel

bookingPanel.html
bookingPanel.js
bookingPanel.js-meta.xml

Walk through it

Build and place it

  1. In your kaveri-dev project, run SFDX: Create Lightning Web Component twice: bookingChecklist and bookingPanel, in force-app/main/default/lwc.
  2. Paste the code. The apiVersion in each meta file can stay as the CLI generated it.
  3. Deploy the folder to Org C, with BookingService from Part A.
  4. Open an opportunity, choose Edit Page, drag Confirm Booking from Custom components onto the page, save and activate.
  5. Book a deal: check the toast, the move to the Order, and the deal's new stage.
  6. Try a ₹5,000 booking, and confirm the error toast shows BookingService's message and nothing was saved.

Practice: Suraksha claim tracker

Build a Claim Tracker for the Case page in Org D, from these requirements. Try it before opening the model answer.

Open the model answer after you've built your own
ClaimTrackerController.cls
claimTracker.html
claimTracker.js
claimTracker.js-meta.xml

Notice: the task list uses a cacheable Apex wire, so after the request it calls refreshApex. The case status comes from Lightning Data Service, so notifyRecordUpdateAvailable refreshes it, along with the standard details on the page.

Three exercises

Exercise 1: Your first component

  1. Build customerCard from the Anatomy section, and place it on the Account page in Org C.
  2. Change it to use the getRecord wire adapter and getters instead of the record view form, showing "Priya Sharma, 98480 11111" as one line.
  3. Add a getter that shows "Repeat customer" when the account has more than one car. Hint: you'll need a cacheable Apex method or a roll-up.

Exercise 2: Booking panel with Lightning Message Service

  1. Build bookingPanel and bookingChecklist from the Demo.
  2. Create the Booking_Updated message channel and publish it after a booking.
  3. Build a small showroomTodayCounter component for the Home page that subscribes to the channel and adds one to "Bookings today" each time.
  4. Test with both components on one Lightning page.

Exercise 3: Find the problem

Build your Component Pack

Record each component: where it appears, its data approach, how it talks to others, and how you tested it. Your work saves in this browser on this device.

Build with AI

AI tools write LWC code quickly, but often use outdated patterns or invent wire adapters. You need to know the right patterns to spot this.

Three rules: Check that every import really exists. Prefer base components and Lightning Data Service over custom Apex where possible. Test as a real user with Step 12's permissions, not as an admin.

A first look at component tests

Step 10 teaches testing in full. Here is the shape of a Jest test for the checklist, to run with the sfdx-lwc-jest tool.

__tests__/bookingChecklist.test.js

Reflect and exit check

Quick test

Exit check: are you ready for Step 6?

What Step 6 needs from you: Integration connects Salesforce to other systems, such as payment gateways and the manufacturer's portal. You'll use Apex callouts, and your components can show what comes back.

Interview preparation

LWC questions appear in most developer interviews. Practise these aloud, then use our AI interview agents for feedback.

For your resume and portfolio

Training project: Built Lightning Web Components for a simulated dealership and insurer: a record-page booking panel with a child component, Apex integration, Lightning Data Service, toasts, navigation and Lightning Message Service, plus a claim tracker with cacheable Apex wires and refresh handling.

Trainer notes

Open the suggested session plan and coaching notes
SessionCoverStudents leave with
1 (90 min)Hook, when to build, anatomy, directives. Build customerCard live.Exercise 1 started
2 (90 min)Data: base components, LDS, wire and imperative Apex. The data drill.Exercise 1 done
3 (90 min)Communication and lifecycle. Live preview, then build the booking panel live.Booking panel working
4 (90 min)Suraksha practice, Exercise 2 with LMS, Exercise 3, code reviews.Component Pack, reflection and exit check

Common mistakes to catch

  • Forgetting the $ in wire parameters, so the wire never reacts to recordId.
  • Calling DML from a cacheable method. Cacheable methods are read-only.
  • Event names with capitals or hyphens. Use lowercase only.
  • Changing an @api value inside the child. Treat it as read-only; tell the parent with an event.
  • Querying the DOM in connectedCallback, before it renders.
  • Not refreshing data after Apex changes it.

Check before each batch

Confirm current base component behaviour and the CLI generator commands. Check the current status of features like the GraphQL wire adapter and the newer toast module before teaching them.