
Building Custom UI Components in Salesforce with Lightning Web Components (LWC)
Salesforce development has moved a long way from old-school Visualforce pages. Today, Lightning Web Components (LWC) is the modern, standards-based framework Salesforce recommends for building fast, reusable UI components — and it’s built directly on native HTML, CSS, and JavaScript.
If you’re a Salesforce developer or admin exploring how to build custom UI on the platform, this week’s post walks through a simple, practical example: a Contact Card component that displays contact details in a clean layout.
Why LWC?
- Performance: LWC uses native browser APIs instead of a proprietary framework, making it lighter and faster than Aura components.
- Standard web technologies: If you know HTML/CSS/JS, you’re already halfway there.
- Reusability: Components can be dropped into Lightning App Builder, Experience Cloud pages, or even used standalone.
- Better testing tools: Jest-based unit testing is built in.
Example: A Simple Contact Card Component
Every LWC component has three core files — an HTML template, a JavaScript controller, and an XML metadata file. Below is the HTML template for a basic contact card:
{contact.Name}
{contact.Title}
{contact.Email}
{contact.Phone}
contactCard.js) that wires up the data and click handler:
import { LightningElement, api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class ContactCard extends NavigationMixin(LightningElement) {
@api contact;
handleViewRecord() {
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: this.contact.Id,
objectApiName: 'Contact',
actionName: 'view'
}
});
}
}
How This Fits Into a Real Org
Once built, this component can be:
- Added to any Lightning record page via App Builder — no code deployment needed for placement.
- Embedded in an Experience Cloud community page for partner or customer portals.
- Reused across multiple objects by simply passing a different
contactrecord as a property.
Key Takeaway
LWC lowers the barrier between traditional web development and Salesforce customization. If your team already has front-end developers comfortable with HTML/CSS/JS, they can start building Salesforce UI components almost immediately — no need to learn a completely proprietary syntax from scratch.
Quick Tips for This Week
- Use
slds(Salesforce Lightning Design System) classes to keep your UI consistent with native Salesforce styling. - Always test components using Jest before deploying to a sandbox.
- Use
@apidecorators to expose properties that parent components or Lightning App Builder can configure.