Salesforce Lightning and LWC interview questions for developers
Salesforce Lightning interview questions are mostly about Lightning Web Components: how a component is built, how it renders and reacts to data, how components talk to each other with events and Lightning Message Service, and how they read Salesforce data through the wire service, Lightning Data Service or Apex. Expect lifecycle hooks, decorators, the bubbles and composed options on events, cacheable Apex and refreshApex, plus questions on Aura, App Builder and Jest tests. Good answers explain what the framework does for you and where it stops.
By Evin JohnPublished 7 min read
How Lightning interviews are run
Front-end Salesforce roles usually have a technical conversation, a code review of a component and sometimes a small build task: a component that shows related records on a record page, with a button that updates one. Interviewers check web fundamentals (JavaScript modules, promises, the DOM) alongside platform knowledge. Questions on Apex and the data model come from the same panel, so revise Salesforce interview questions for triggers and sharing, and the JavaScript interview questions guide for the language underneath.
LWC fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What files make up a Lightning web component? | Structure | An HTML template, a JavaScript class that extends LightningElement, an optional CSS file, and a js-meta.xml file that sets where the component can be used and which properties App Builder can configure. |
| Lightning Experience versus Classic? | Context | Lightning Experience is the modern interface built from components and pages. Classic is the older interface. New features and nearly all component work target Lightning Experience. |
| LWC versus Aura? | Frameworks | LWC uses web standards (custom elements, modules, shadow DOM) and is lighter. Aura is the older proprietary model. Aura components can contain LWCs, not the reverse, so mixed apps wrap LWCs in Aura where needed. |
| What do @api, @wire and @track do? | Decorators | @api makes a property or method public to the parent. @wire connects a property or function to a data source. Fields are reactive by default; @track is needed only to see changes inside an object or array without reassigning it. |
| Why can't I write expressions in a template? | Templates | Templates allow only property references. Compute values in a getter in the JavaScript class, which keeps logic testable. |
| Why does for:each need a key? | Lists | The key gives each item a stable identity so the engine can update only what changed. Use a record Id, never the array index if the list can reorder. |
| How do you show or hide markup? | Conditional rendering | With lwc:if, lwc:elseif and lwc:else in newer code, or the older if:true and if:false directives. Hidden branches are not rendered at all. |
| How do you make a component available in App Builder? | Metadata | Set isExposed to true in js-meta.xml and list targets such as record, app and home pages; targetConfigs define design properties admins can set. |
| How do you style a component? | CSS | With the component's own CSS file, scoped by shadow DOM, and Lightning Design System classes or styling hooks. Styles from outside do not leak in. |
| How do you query elements inside a component? | DOM access | this.template.querySelector for the component's own template. You cannot reach into a child's shadow tree; ask the child through an @api method. |
Lifecycle and communication
- Which lifecycle hooks exist? constructor (call super first, no attribute or child access), connectedCallback when inserted into the DOM, renderedCallback after every render, disconnectedCallback when removed, and errorCallback on a parent to catch errors from its children.
- What is the classic renderedCallback bug? Setting a reactive property inside it triggers another render, which calls it again. Guard with a flag or move the work to connectedCallback.
- Where should you clean up? In disconnectedCallback: remove window listeners, clear intervals and unsubscribe from message channels, or the component leaks after it leaves the page.
- How does a child tell its parent something? It dispatches a CustomEvent with a lowercase name and a detail payload. The parent listens in its template with on plus the event name.
- What do bubbles and composed mean? Both default to false. bubbles lets the event go up the DOM tree; composed lets it cross shadow boundaries. Using both makes an event visible far beyond the parent, so turn them on only when you mean to.
- How do unrelated components communicate? Lightning Message Service, which publishes on a message channel that subscribers anywhere on the page receive, including across LWC, Aura and Visualforce.
- How does a parent call a child's method? Mark the method @api in the child, then get the child with querySelector and call it. Use it sparingly; data passed down through properties is easier to follow.
// contactTile.js (child)
import { LightningElement, api } from 'lwc';
export default class ContactTile extends LightningElement {
@api contact; // passed down by the parent
handleClick() {
this.dispatchEvent(new CustomEvent('select', {
detail: { contactId: this.contact.Id }
})); // bubbles and composed stay false
}
}
// contactList.js (parent)
import { LightningElement } from 'lwc';
export default class ContactList extends LightningElement {
selectedId;
handleSelect(event) {
this.selectedId = event.detail.contactId;
}
}Working with Salesforce data
| Question | What it tests | What a strong answer shows |
|---|---|---|
| Wire service or imperative Apex? | Data access | Wire is declarative and reactive: it reprovisions when a $-prefixed parameter changes and uses the client cache. Imperative calls return a promise and suit actions on a click and any method that changes data. |
| Why must a wired Apex method be cacheable? | Apex rules | Wired methods need @AuraEnabled(cacheable=true), which marks them as read-only so results can be cached. Methods that do DML cannot be cacheable and are called imperatively. |
| How do you refresh wired data after a change? | Cache | Keep the full wired result and pass it to refreshApex after the update. For record data changed outside LDS, notify LDS so other components update too. |
| What is Lightning Data Service? | Platform data layer | A shared client-side cache for records that respects sharing and field-level security. Components showing the same record stay in sync without Apex. |
| When do you use lightning-record-form versus record-edit-form? | Base components | record-form builds a full view or edit form from a layout or field list with almost no code. record-edit-form and record-view-form let you place each field yourself and customize handling. |
| Why import fields from @salesforce/schema? | References | The platform knows the component depends on that field, which blocks deleting or renaming it and catches typos at deploy time. |
| How do you handle errors from Apex in a component? | Error handling | Read the error body, show a clear message with a toast or inline, and log details. Throw AuraHandledException in Apex with a message meant for users. |
| Does Apex called from LWC respect the user's access? | Security | Not automatically. Declare the class with sharing and enforce object and field access with user-mode queries or by stripping inaccessible fields; LDS does this for you. |
import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import NAME from '@salesforce/schema/Account.Name';
import INDUSTRY from '@salesforce/schema/Account.Industry';
export default class AccountHeader extends LightningElement {
@api recordId; // set by the record page
@wire(getRecord, { recordId: '$recordId', fields: [NAME, INDUSTRY] })
account;
get name() { return getFieldValue(this.account.data, NAME); }
get industry() { return getFieldValue(this.account.data, INDUSTRY); }
get error() { return this.account.error; }
}Senior and scenario questions
- A component works in the sandbox but shows nothing for some users in production. Why? Usually access: the user lacks permission on the Apex class, the object or a field, or the record is not shared with them. Check the browser console and the error returned before touching code.
- A record page with many components feels slow. What do you do? Prefer LDS and cacheable reads over repeated Apex calls, load secondary data lazily (on tab activation or scroll), paginate large lists, and avoid heavy work in renderedCallback. Measure with the browser's performance tools.
- What are Lightning Locker and Lightning Web Security? Security layers that isolate components from different namespaces so one cannot read or tamper with another. Lightning Web Security is the newer approach based on JavaScript sandboxing; know which one your org uses because some third-party libraries behave differently.
- How do you load a third-party library? Upload it as a static resource and load it with the platform's script loader in a lifecycle hook, once, then check it works under the org's security layer.
- How do you navigate between pages? NavigationMixin with a page reference for record pages, list views, named pages or web pages, rather than hardcoded URLs that break across orgs.
- How do you test LWCs? Jest with the Salesforce LWC Jest setup: create the element, attach it to the DOM, emit mock data from wire adapters, and assert the rendered output. Tests run locally without an org.
- When would you still build in Aura? Mainly when maintaining existing Aura apps or a context that needs an Aura wrapper. New work goes in LWC.
- How do LWCs fit with Flow? A component can be exposed to screen flows as a custom screen element, with @api properties as inputs and outputs, so admins reuse developer components.
Fictional example
- Interviewer
- A component wires a cacheable Apex method to list open cases. A button calls another Apex method to close one. The save works, but the closed case stays in the list until reload. Why?
- Candidate
- The wired result is cached, and nothing told the wire service the data changed, so it keeps serving the old list. The fix is to keep the whole wired result in a property instead of just the data, then call refreshApex on it after the close succeeds, inside the promise chain so it runs only on success. I would also show a toast for success and for errors from the imperative call. If other components on the page show the same case through LDS, I would notify LDS that the record changed so they refresh too. Finally I would add a Jest test that emits mock data, clicks the button with the Apex call mocked, and checks that the refresh happened.
How to prepare for Salesforce Lightning interview questions
- Build a record page componentRead fields with getRecord, list related records with cacheable Apex, update one imperatively and refresh the list.
- Wire up communicationA parent and child with properties and a custom event, then two unrelated components talking through a message channel.
- Break things on purposeSet state in renderedCallback, leave a key off a list, remove field access from a test user, and watch what happens.
- Write Jest testsMock a wire adapter and an Apex call and assert the DOM. Interviewers increasingly ask how you test components.
- Rehearse explanationsLifecycle order, bubbles versus composed, and wire versus imperative, each in under a minute.
Components land on pages admins configure, so Salesforce admin interview questions is worth a read to understand App Builder and record pages from their side, and Jest interview questions helps with the testing questions.
Explaining reactivity and caching clearly takes a few tries. Natively, an AI interview assistant for Mac and Windows, transcribes a mock LWC round on your computer so you can hear whether your wire versus imperative answer made sense. In practice it can read a component or a console error from a screenshot and suggest a fix to discuss, and with Pro or the free trial it can work with the résumé and job description you add. The transcript and notes of each mock stay with you for review.
Questions people ask
What are common Salesforce Lightning interview questions?
LWC versus Aura, component files and js-meta.xml, lifecycle hooks, @api, @wire and @track, template directives and keys, custom events with bubbles and composed, Lightning Message Service, wire versus imperative Apex, Lightning Data Service and Jest testing.
What is the difference between wire and imperative Apex calls in LWC?
Wire is declarative, reactive to parameter changes and cached, and needs a cacheable Apex method. Imperative calls return a promise, run when you call them, and are used for actions and methods that change data.
What are the LWC lifecycle hooks?
constructor, connectedCallback, renderedCallback, disconnectedCallback and errorCallback. Avoid setting reactive state in renderedCallback without a guard, and clean up listeners in disconnectedCallback.
Is Aura still asked in Salesforce Lightning interviews?
Sometimes, mainly how it differs from LWC and how the two interoperate. Aura can contain LWCs but not the reverse, and new work is normally built in LWC.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
