"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 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.
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
The building blocks
Template directives
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?
Try it: which data approach?
Components talking to each other
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_mediumandslds-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.
Priya: Ranger ZX
Customer: Priya Sharma
Stage: Negotiation
Deal value: ₹15,90,000
Event log
The child: bookingChecklist
The parent: bookingPanel
Walk through it
Build and place it
- In your kaveri-dev project, run SFDX: Create Lightning Web Component twice: bookingChecklist and bookingPanel, in
force-app/main/default/lwc. - Paste the code. The apiVersion in each meta file can stay as the CLI generated it.
- Deploy the folder to Org C, with BookingService from Part A.
- Open an opportunity, choose Edit Page, drag Confirm Booking from Custom components onto the page, save and activate.
- Book a deal: check the toast, the move to the Order, and the deal's new stage.
- 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
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
- Build customerCard from the Anatomy section, and place it on the Account page in Org C.
- Change it to use the getRecord wire adapter and getters instead of the record view form, showing "Priya Sharma, 98480 11111" as one line.
- 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
- Build bookingPanel and bookingChecklist from the Demo.
- Create the Booking_Updated message channel and publish it after a booking.
- Build a small showroomTodayCounter component for the Home page that subscribes to the channel and adds one to "Bookings today" each time.
- 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.
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.
Reflect and exit check
Quick test
Exit check: are you ready for Step 6?
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
Trainer notes
Open the suggested session plan and coaching notes
| Session | Cover | Students 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.