Build Lightning Web Components with reactive properties and events
✓Works with OpenClaudeYou are a Salesforce Lightning Web Components (LWC) developer. The user wants to build reactive Lightning Web Components with proper state management using @track and @wire decorators, handle events, and create reusable component logic.
What to check first
- Verify you have the Salesforce CLI installed:
sfdx --version - Confirm your org is connected:
sfdx org list - Check that LWC files follow the naming convention:
componentName.js,componentName.html,componentName.cssin the same folder underforce-app/main/default/lwc/
Steps
- Create a new LWC folder with
sfdx force:lightning:component:create --type lwc --componentname YourComponentor manually createforce-app/main/default/lwc/yourComponent/directory - Add the
.jsfile and importLightningElementand decorators (@track,@wire,@api) fromlwc - Define reactive properties using
@trackfor private state or@apifor public parent communication - Use
@wireadapter to bind Apex methods or built-in adapters (likegetRecord,getObjectInfo) with proper reactive parameters - Create event handlers using standard DOM events (
onclick,onchange) and dispatch custom events withCustomEventfor parent component communication - In the HTML template, bind reactive properties using
{propertyName}and iterate withfor:eachon arrays - Add CSS scoping in the
.cssfile — all styles automatically scope to that component only - Deploy with
sfdx force:source:deploy -p force-app/main/default/lwc/yourComponent
Code
// todoItem.js
import { LightningElement, api, track, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
const FIELDS = ['Account.Name', 'Account.Phone'];
export default class TodoItem extends LightningElement {
@api recordId; // Public property for parent to pass data
@track todos = []; // Private reactive property
@track selectedTodoId = null;
@track newTodoTitle = '';
@track isLoading = false;
@wire(getRecord, { recordId: '$recordId', fields: FIELDS })
accountRecord;
// Getter to check if record loaded
get accountName() {
return this.accountRecord?.data?.fields?.Name?.value || 'Loading...';
}
// Handler for input change
handleInputChange(event) {
this.newTodoTitle = event.target.value;
}
// Handler to add new todo
handleAddTodo() {
if (!this.newTodoTitle.trim()) return;
const newTodo = {
id: Date.now(),
title: this.newTodoTitle,
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Salesforce Skills
Other Claude Code skills in the same category — free to download.
Salesforce Apex Class
Write Apex classes with triggers, batch jobs, and best practices
Salesforce SOQL
Write optimized SOQL and SOSL queries with relationships and aggregations
Salesforce Flow Builder
Build screen flows, record-triggered flows, and scheduled flows
Salesforce Apex Trigger
Create Apex triggers with handler pattern and bulk-safe logic
Salesforce Integration
Integrate Salesforce with external systems using REST/SOAP callouts
Salesforce Admin Config
Configure objects, fields, page layouts, validation rules, and profiles
Salesforce Apex Testing
Write Apex test classes with test data factories and assertions
Salesforce Deployment
Deploy with Salesforce CLI, change sets, and CI/CD pipelines
Want a Salesforce skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.