Courseiva

CCNA User Interface Questions

39 questions · User Interface · All types, answers revealed

1
MCQhard

A developer is building a Lightning Web Component that needs to navigate to a specific record page when a user clicks a button. The developer wants to use the NavigationMixin from lightning/navigation. The component is a child component nested inside another component, and the developer needs to ensure that the navigation works correctly. Which code snippet correctly uses NavigationMixin to navigate to an Account record page?

A.this[NavigationMixin.Navigate]({ type: 'standard__recordPage', attributes: { recordId: '001...', objectApiName: 'Account', actionName: 'view' } });
B.NavigationMixin.Navigate(this, { type: 'standard__recordPage', attributes: { recordId: '001...', objectApiName: 'Account', actionName: 'view' } });
C.this[NavigationMixin.Navigate](pageReference); where pageReference is defined as a string URL.
D.this.NavigationMixin.Navigate({ type: 'standard__recordPage', attributes: { recordId: '001...', objectApiName: 'Account', actionName: 'view' } });
AnswerA

This snippet correctly uses the NavigationMixin.Navigate method with a page reference object. The type 'standard__recordPage' is used to navigate to a record page, and the attributes specify the recordId, objectApiName, and actionName. This is the standard way to navigate to a record page in LWC using NavigationMixin.

Why this answer

The correct code uses this[NavigationMixin.Navigate] with a page reference object of type 'standard__recordPage'. This is the standard pattern for navigation in LWC. The mixin is applied to the class, and the Navigate method is accessed via bracket notation on the instance.

The other options either use incorrect syntax or pass invalid arguments.

Exam trap

The trap here is using dot notation instead of bracket notation for the mixed-in Navigate method, or assuming Navigate can be called statically.

2
MCQmedium

A developer is building a Lightning Web Component that should be embedded inside a Visualforce page. The LWC must receive a parameter passed from the Visualforce page and send an event back when a button is clicked. Which combination of features enables this integration?

A.lightning:container and Lightning Message Service, using the published message channel to pass both the parameter and the return event.
B.A Visualforce remoting call using JavaScript remoting to invoke the LWC's controller and pass the parameter as a method argument.
C.Lightning Out with a dependency app, passing the parameter via the component attribute and receiving the event through a callback registered on the app.
D.An Aura component wrapper using lightning:isUrlAddressable, passing the parameter through the URL and reading it with the navigation mixin.
AnswerC

Lightning Out is the supported way to render an LWC inside a Visualforce page. A dependency app exposes the component, the VF page uses $Lightning.use and $Lightning.createComponent to instantiate it, attributes pass the parameter in, and an event handler registered during creation receives events the LWC fires. This accurately matches the required inbound parameter and outbound event pattern for VF-to-LWC integration.

Why this answer

Embedding an LWC in Visualforce requires Lightning Out: a dependency app declares the component, and the VF page instantiates it with $Lightning.use and $Lightning.createComponent. Attributes carry the inbound parameter, and an event handler supplied during creation receives events the component fires. Lightning Message Service, URL-addressable Aura wrappers, and JavaScript remoting each address different problems and cannot both pass a parameter in and return an event out in this context.

Exam trap

The trap here is assuming Lightning Message Service alone can embed an LWC in Visualforce, when embedding actually requires Lightning Out with a dependency app.

3
MCQeasy

A developer is building a Lightning Web Component that includes a button. When the button is clicked, the component must navigate the user to a specific Account record page in Lightning Experience. Which approach should the developer use?

A.Use the lightning-formatted-url component with the record ID and target set to _self.
B.Set window.location.href to the record's URL constructed from the Salesforce instance domain.
C.Call the Apex method that returns the record URL and then assign it to a property bound to an anchor tag.
D.Use the NavigationMixin from lightning/navigation and call this[NavigationMixin.Navigate] with a standard__recordPage page reference.
AnswerD

NavigationMixin adds a navigate method to the component. Passing a page reference with type standard__recordPage and the recordId attribute directs the user to the record's page in Lightning Experience. This is the supported way to perform client-side navigation from an LWC without a full page reload, and it works across Lightning Experience and the Salesforce mobile app.

Why this answer

NavigationMixin provides a navigate method that accepts a page reference object. For a record page, the page reference type is standard__recordPage with the recordId and actionName attributes. This performs client-side navigation within Lightning Experience, preserving the app context and working in the mobile app.

It is the documented, supported pattern for navigating from an LWC.

Exam trap

The trap here is using a full page reload via window.location or an anchor tag instead of the client-side NavigationMixin, which preserves the Lightning Experience context.

4
MCQhard

A developer is building a Lightning Web Component that must display a toast notification when a record is saved successfully. The component uses lightning/platformShowToastEvent. Which import and usage are correct?

A.Import ShowToastEvent from lightning/platformShowToastEvent and dispatch it with new ShowToastEvent({ title, message, variant }).
B.Use the lightning-toast base component and set its title, message, and variant attributes in the template.
C.Import toast from lightning/toast and call toast.show({ title, message, variant }).
D.Import ShowToastEvent from lightning/platformShowToastEvent and call this.ShowToastEvent({ title, message, variant }) without dispatching.
AnswerA

The ShowToastEvent module is imported from lightning/platformShowToastEvent. Creating a new instance with title, message, and variant properties and dispatching it via this.dispatchEvent displays a toast in Lightning Experience and the Salesforce mobile app. This is the standard, supported way to show toasts from an LWC.

Why this answer

To display a toast from an LWC, import the ShowToastEvent class from lightning/platformShowToastEvent, instantiate it with title, message, and variant, and dispatch it from the component. The event bubbles to the Lightning Experience toast container, which renders the notification. This works consistently across Lightning Experience and the Salesforce mobile app.

Exam trap

The trap here is assuming a declarative toast component or a method-based API exists, when the platform requires instantiating and dispatching a ShowToastEvent.

5
MCQeasy

A developer needs a Lightning Web Component to navigate the user to a specific Account record's detail page when a button is clicked. Which approach is correct?

A.Import NavigationMixin from lightning/navigation, extend the component class with it, and call this[NavigationMixin.Navigate] with a standard__recordPage page reference.
B.Use window.location.href to set the browser URL to the record's Id appended to the Salesforce instance domain.
C.Call an Apex method annotated with @AuraEnabled that returns the record's URL and assign it to an anchor's href attribute.
D.Import the lightning:navigation base component, place it in the template, and set its recordId attribute to the Account Id.
AnswerA

NavigationMixin from lightning/navigation provides client-side navigation in LWC. Extending the class with it and calling this[NavigationMixin.Navigate] with a page reference of type standard__recordPage and the record's Id navigates to the record detail page without a full page reload. This is the documented, supported pattern for this exact requirement.

Why this answer

Client-side navigation in a Lightning Web Component is handled by the NavigationMixin from lightning/navigation. Extending the component class with the mixin and calling the Navigate method with a standard__recordPage page reference moves the user to the Account record page without a full reload. Manually setting the browser location, inventing a navigation base component, or fetching a URL from Apex all bypass the supported API and degrade the user experience.

Exam trap

The trap here is looking for a declarative navigation base component, when navigation in LWC is actually performed through the NavigationMixin JavaScript mixin.

6
MCQhard

Refer to the exhibit. A developer is attempting to push source code to a scratch org and encounters the error shown. The developer confirms that 'utils.js' and 'utils.js-meta.xml' exist in the 'force-app/main/default/lwc/utils/' directory. What is the most likely cause of this error?

A.The developer forgot to add the '@salesforce/resource' prefix to the import.
B.The 'utils' component is missing the 'isExposed' tag in its metadata file.
C.The main JavaScript file in the 'utils' folder must be named 'utils.js'.
D.The developer needs to run 'sfdx force:source:pull' first to sync metadata.
AnswerC

In LWC, the main JavaScript file of a component must have the exact same name as the folder it resides in. If the folder is named 'utils', the framework expects a file named 'utils.js'. If the file is named differently, the 'c/utils' import path will fail to resolve during the compilation process.

Why this answer

LWC requires a specific file structure and naming convention for components and modules. When importing a local module, the framework looks for a component folder and a corresponding main JavaScript file. If the main file name does not match the folder name, the compiler cannot resolve the import, leading to deployment failures.

Exam trap

Candidates often assume the error is related to XML configuration or file permissions, missing the strict LWC requirement that the JavaScript filename must match the folder name.

7
MCQmedium

A developer has a Lightning Web Component named accountTile that exposes a public property accountName decorated with @api. A parent Aura component includes accountTile using <c:accountTile accountName="Acme"/>. During testing, the account name never appears. The developer confirms the property is set in the LWC constructor. What is the cause?

A.The property is read in the LWC constructor, but attribute values passed from an Aura parent are not available until after the component is connected.
B.The @api property must be defined as a getter/setter pair to accept values from an Aura parent.
C.Aura components cannot pass attributes to Lightning Web Components unless the LWC is wrapped in an <aura:component>.
D.The attribute name must be prefixed with aura: to be recognized across the Aura-to-LWC boundary.
AnswerA

When an Aura parent supplies attributes to a Lightning Web Component, those values are applied after the component is constructed, so reading the @api property inside the constructor returns undefined. The developer should read the value in a lifecycle hook such as connectedCallback or renderedCallback, or use a setter, to observe the value reliably.

Why this answer

Values supplied by an Aura parent land on a Lightning Web Component after construction, so a plain @api property is undefined inside the constructor. Reading it in connectedCallback or renderedCallback, or converting it to a setter, lets the component react once the value is present. The scenario is a lifecycle-timing problem, not a missing-accessor or wrapper problem.

Exam trap

The trap here is assuming that an @api property is populated before the constructor runs, when in fact parent-supplied attributes arrive after construction.

8
MCQeasy

A developer is creating a Lightning Web Component that includes a button. When the button is clicked, the component should call an Apex method to save data. Which decorator should be used to expose the Apex method to the Lightning Web Component?

A.@RemoteAction
B.@InvocableMethod
C.@Future
D.@AuraEnabled
AnswerD

The @AuraEnabled decorator is used on Apex methods to expose them to Lightning Web Components and Aura components. When applied to a static method, it makes the method available for invocation from the client-side JavaScript. For LWC, the method must be static and can be called using the wire service or imperatively. This is the standard way to call Apex from LWC. Without @AuraEnabled, the method cannot be called from the component.

Why this answer

The @AuraEnabled decorator is the correct choice because it exposes an Apex method to Lightning Web Components and Aura components. When a method is annotated with @AuraEnabled, it can be called from the component's JavaScript using the wire service or imperatively. The other decorators serve different purposes: @RemoteAction is for Visualforce, @InvocableMethod is for declarative tools, and @Future is for asynchronous processing.

Only @AuraEnabled enables direct invocation from LWC.

Exam trap

The trap here is confusing @AuraEnabled with other Apex decorators like @RemoteAction or @InvocableMethod, which are used in different contexts.

9
MCQhard

A developer is building a Lightning Web Component that must call an Apex method that performs a callout. The component is placed on a Lightning record page, and the Apex method is annotated with @AuraEnabled(cacheable=true). Users report that the callout never executes and an error is thrown. What is the most likely cause and the correct fix?

A.The callout is blocked by the component's Lightning locker service; disable locker service for the component in Setup.
B.The error occurs because the Apex method must be annotated with @AuraEnabled(cacheable=true) to allow callouts; add the annotation.
C.The callout fails because Lightning Web Components cannot call Apex methods that perform callouts; use a Visualforce remoting call instead.
D.The callout is blocked because @AuraEnabled(cacheable=true) methods cannot perform callouts; remove cacheable=true or move the callout to a method without caching.
AnswerD

Methods marked with @AuraEnabled(cacheable=true) are executed in a read-only context and are subject to restrictions that prevent DML and callouts. Attempting a callout from a cacheable method throws an error. Removing cacheable=true or separating the callout into a non-cacheable method allows the callout to execute, though it loses the client-side caching benefit.

Why this answer

Apex methods annotated with @AuraEnabled(cacheable=true) run in a read-only context that prohibits callouts and DML. When such a method attempts a callout, Salesforce throws an error before the callout is made. The correct resolution is to remove cacheable=true or to move the callout into a separate non-cacheable method that the component invokes directly, allowing the callout to proceed while keeping any cacheable read logic separate.

Exam trap

The trap here is assuming that cacheable=true is always beneficial for performance, when it actually forbids callouts and DML in the method body.

10
MCQmedium

A developer is creating a Lightning Web Component to display a list of high-priority Opportunities. The component needs to reactively update whenever an Opportunity is updated elsewhere on the page by another component. Which approach is most efficient and requires the least amount of custom code?

A.Use the getRecord wire adapter to retrieve Opportunity data.
B.Implement an Apex controller with a @AuraEnabled(cacheable=true) method.
C.Publish a message via Lightning Message Service (LMS) after every update.
D.Set up a Change Data Capture (CDC) listener in the component.
AnswerA

The getRecord wire adapter is built on Lightning Data Service, which maintains a client-side cache. If any other component updates the Opportunity record using LDS, the wire service automatically triggers a refresh for all components observing that record, ensuring data consistency across the UI without requiring custom refresh logic.

Why this answer

Lightning Data Service (LDS) provides a managed cache that is shared across all components in a Lightning page. When a record is updated via LDS in one component, all other components wired to that same record or using LDS wire adapters automatically receive the updated data. This eliminates the need for manual event handling or complex state management.

Exam trap

Candidates often suggest using custom events or platform events to synchronize data between components, failing to realize that LDS wire adapters provide this reactivity automatically without any code.

11
MCQhard

A developer is building a Lightning Web Component that must expose a method to an Aura component wrapper so the Aura component can call it after a user action. The LWC method is decorated with @api and named doSomething. Which code in the Aura component correctly invokes it?

A.component.getReference('c.doSomething')();
B.component.find('myLwc').call('doSomething');
C.component.find('myLwc').get('c.doSomething')();
D.component.find('myLwc').doSomething();
AnswerB

To invoke a public method on a Lightning Web Component from an Aura component, you use the call() method on the found element with the method name as a string. This is the documented interop pattern. Arguments would be passed as a second parameter object if the LWC method accepted them.

Why this answer

Aura components invoke public Lightning Web Component methods through the call() method on the element returned by find(), passing the method name as a string. Plain function calls, the Aura get('c.method') accessor, and getReference do not reach an LWC's @api methods and fail at runtime.

Exam trap

The trap here is applying the Aura controller method syntax get('c.method') to a Lightning Web Component, when LWC methods are invoked with call().

12
MCQmedium

A developer is building a Lightning Web Component for a Lightning Experience app. The component contains a form with an <input> for a search term and a list of results. When the user types into the input, the component must call an Apex method that returns matching records. The developer observes that the Apex method is being invoked on every keystroke, causing excessive server calls. Which technique should the developer use to limit the number of Apex calls while still updating the results as the user types?

A.Set the Apex method to cacheable=true and call it imperatively from the component's JavaScript.
B.Implement a debounce function using setTimeout and clearTimeout to delay the Apex call until the user pauses typing.
C.Use the lightning-input component with the onchange event and call the Apex method only when the input value length exceeds three characters.
D.Use the @wire decorator with the Apex method and pass the search term as a reactive parameter.
AnswerB

Debouncing delays the Apex call until a period of inactivity has passed after the last keystroke. This reduces the number of calls to one per pause, which is the standard technique for limiting server calls in LWC. It is the correct approach because it controls the timing of imperative Apex calls.

Why this answer

Debouncing is the correct technique to limit Apex calls triggered by rapid user input. By delaying the call until the user pauses typing, the component reduces server load while still providing timely results. Other options either do not control timing or do not effectively reduce the number of calls in this scenario.

Exam trap

The trap here is assuming that @wire automatically debounces or that cacheable=true reduces call frequency when parameters change.

13
MCQhard

An enterprise Salesforce implementation requires a Lightning Web Component to display massive amounts of tabular data with extremely high rendering performance. The standard lightning-datatable component fails to meet performance SLAs during stress testing. Which architectural approach should the developer implement to optimize rendering performance?

A.Implement a custom virtual scrolling component that dynamically renders only the rows visible within the current viewport and recycles DOM elements during scroll events.
B.Wrap the standard lightning-datatable inside an Aura component and leverage the deprecated locker service bypass configuration to speed up internal data grid rendering cycles.
C.Increase the Locker Service strictness level in the Organization Security settings to force asynchronous thread rendering for all tabular user interface components.
D.Utilize native browser web workers to fetch, sort, and directly manipulate the document object model outside of the main Lightning Web Component rendering thread.
AnswerA

Virtual scrolling keeps the DOM lightweight by rendering just a fraction of the total dataset at any given time, preventing browser lag and memory exhaustion when handling tens of thousands of records in a single table.

Why this answer

When standard components fail due to DOM node limits and heavy memory footprints with large datasets, developers must implement a custom virtual scrolling mechanism. Virtual scrolling renders only the visible rows in the viewport and recycles DOM elements as the user scrolls, drastically reducing memory usage and maintaining smooth sixty frames per second rendering.

Exam trap

Developers often attempt to solve performance bottlenecks by writing recursive wire adapters or leveraging native browser print styling, overlooking that DOM node bloat is the root cause.

14
Multi-Selecthard

A developer is creating a Lightning Web Component that needs to display a list of Contacts for a given Account. The component will be placed on a Lightning record page for Account. The developer wants to use the getRelatedListRecords wire adapter from lightning/uiRelatedListApi to fetch the contacts. Which two parameters are required in the wire configuration object for getRelatedListRecords? (Choose two.)

Select 2 answers
A.sortBy
B.fields
C.relatedListId
D.pageSize
E.parentRecordId
AnswersC, E

relatedListId is required to specify the API name of the related list, such as 'Contacts' for the Contacts related list on Account. This tells the adapter which related list to query. Without it, the adapter does not know which child relationship to traverse. The developer must provide the correct related list API name to retrieve the Contacts.

Why this answer

The getRelatedListRecords wire adapter requires two parameters: parentRecordId and relatedListId. parentRecordId identifies the parent record (Account) whose related list is queried, and relatedListId specifies which related list (e.g., Contacts) to retrieve. Optional parameters like fields, sortBy, and pageSize can refine the results but are not mandatory for the adapter to execute.

Exam trap

The trap here is assuming that fields or sortBy are required because they are commonly used, when in fact only parentRecordId and relatedListId are mandatory.

15
MCQhard

A developer is experiencing performance issues with a Visualforce page that includes multiple complex components and a large amount of data. The page uses a standard controller with several extensions. Which technique should the developer use to reduce the view state size and improve page load time?

A.Mark non-essential controller variables with the 'transient' keyword.
B.Replace the standard controller with a custom controller using 'without sharing'.
C.Wrap all input fields in an <apex:actionRegion> component.
D.Increase the 'apiVerson' in the Visualforce page metadata to the latest version.
AnswerA

The transient keyword prevents a variable from being included in the Visualforce view state. This is highly effective for large collections or temporary data that only needs to exist during the current request. By reducing the view state size, the developer decreases the payload sent over the network.

Why this answer

Visualforce view state can significantly impact performance, as it is sent back and forth between the client and server. Minimizing the data stored in the view state is essential. Using the transient keyword on variables that do not need to persist across postbacks is a primary optimization technique for Visualforce developers.

Exam trap

Candidates often confuse 'transient' with 'static' or other modifiers, incorrectly thinking it relates to caching or performance optimization rather than specifically excluding data from the view state.

16
MCQmedium

A developer is building a Lightning Web Component that must navigate to a new record's detail page after the record is created via a custom form. The component uses NavigationMixin. Which navigation type should the developer use to navigate to the newly created record?

A.standard__webPage with attributes url set to the record's URL.
B.standard__objectPage with attributes objectApiName and actionName set to 'new'.
C.standard__navItemPage with attributes apiName set to the object's API name.
D.standard__recordPage with attributes recordId and actionName set to 'view'.
AnswerD

The standard__recordPage page reference navigates to a record's detail page and accepts recordId and actionName attributes. Setting actionName to 'view' opens the record in view mode. After creating the record, the developer can pass the returned record ID to this page reference to navigate the user directly to the new record, which is the standard pattern for post-creation navigation.

Why this answer

NavigationMixin supports several page reference types, and standard__recordPage is specifically designed to open a record's detail page. By providing the recordId of the newly created record and setting actionName to 'view', the component navigates the user to the standard record view. Other page reference types target object home pages, custom tabs, or external URLs and do not open a specific record.

Exam trap

The trap here is confusing standard__objectPage with standard__recordPage, since both relate to objects but only the latter targets a specific record.

17
Multi-Selecthard

A developer is building a Lightning Web Component that must expose a public method callable from an Aura component on the same page. The method accepts a string and returns a promise that resolves with a boolean. Which TWO steps are required to make this method callable from the Aura parent? (Choose two.)

Select 2 answers
A.Annotate the method with @api and declare it as a public property or method on the Lightning Web Component class.
B.In the Aura parent, use the aura:component's find method or a template query to obtain the element, then invoke the method on that element reference.
C.Register the method name in the component's .js-meta.xml file under the targetConfigs section.
D.Wrap the Lightning Web Component inside an aura:method declaration so the Aura parent can call it directly.
E.Add the method to the component's exported functions list using the export keyword alongside the @api decorator.
AnswersA, B

The @api decorator exposes a class member as part of the component's public API. When a method is decorated with @api, the Lightning Web Component framework registers it so that parents, including Aura components, can invoke it through the element reference. Without this decorator the method remains private and is not addressable from outside the component, regardless of how the parent tries to call it.

Why this answer

Exposing a Lightning Web Component method to an Aura parent requires two things: the method must be decorated with @api so the framework registers it as public, and the Aura parent must obtain the element reference, typically via component.find with an aura:id, to call that method. The promise returned is handled asynchronously by the Aura caller, matching the stated contract.

Exam trap

The trap here is believing that metadata files or Aura-specific constructs like aura:method are needed to expose a Lightning Web Component method, when the only requirement is the @api decorator plus an element reference in the parent.

18
Multi-Selectmedium

A developer is tasked with internationalizing a Lightning Web Component that will be deployed globally. Which TWO Salesforce features should be used to handle locale-specific formatting and translations? (Choose TWO)

Select 2 answers
A.@salesforce/i18n import statements
B.Translation Workbench and Custom Labels
C.Apex Schema.DescribeFieldResult labels
D.Hardcoded JSON files in Static Resources
E.Lightning Message Service (LMS)
AnswersA, B

The @salesforce/i18n module provides access to locale-specific settings such as currency codes, date formats, and time zones. By importing these values, developers can use standard JavaScript Intl objects or framework utilities to format data correctly for every user, regardless of their geographical location or language settings.

Why this answer

Internationalization (i18n) in LWC involves both translating text and formatting data like dates or currencies. Salesforce provides built-in modules to access user preferences and custom translations. Using these features ensures that the UI remains consistent with the user's locale settings and provides a localized experience without hardcoding values or formats in the component.

Exam trap

Candidates often suggest hardcoding translations or using standard Apex, forgetting that LWC has specific 'i18n' modules and that Custom Labels are the standard for text localization.

19
MCQmedium

A developer is building a Lightning Web Component that must render a large list of order records retrieved from Apex. The component displays each order's formatted total, which follows the user's locale (for example, 1.234,56 € in Germany versus $1,234.56 in the US). Which approach correctly formats each order total for the current user?

A.Use the toLocaleString() method on the JavaScript Number object inside the component's renderedCallback.
B.Call the Apex method with a @AuraEnabled(cacheable=true) annotation and rely on Apex to return the formatted string.
C.Bind the raw numeric field from Apex directly into the template and let the browser's Intl.NumberFormat format it automatically.
D.Import the formatNumber function from lightning/i18n and call it with the numeric value and the appropriate format string.
AnswerD

lightning/i18n exposes formatNumber, which formats values according to the running user's Salesforce locale. This keeps the displayed total aligned with the user's language and region settings and matches how Salesforce formats numbers elsewhere. Using it avoids browser-locale drift and keeps formatting consistent across the org's users regardless of their OS or browser settings.

Why this answer

Formatting numbers for the running user requires respecting the Salesforce locale, not the browser locale. The lightning/i18n module's formatNumber function is the supported way to format numeric values client-side so results match the user's Salesforce locale. Relying on browser-based formatting or Apex-side string concatenation produces inconsistent output across users and locales.

Exam trap

The trap here is assuming the browser's locale matches the Salesforce user's locale setting, which is not guaranteed in Lightning Experience.

20
MCQhard

A developer has a Lightning Web Component that must call an imperative Apex method to save a record, then immediately display a toast confirming success only if the save actually succeeded. The Apex method returns a wrapper with a Boolean success flag and a message. Which imperative call pattern correctly handles both the success and error paths?

A.Use .then() to read the wrapper's success flag and conditionally fire the success toast, and .catch() to handle any Apex exception with an error toast.
B.Wrap the imperative call in a wire adapter and use the wired property's data and error values to drive the toasts.
C.Invoke the Apex method and use a setTimeout of 500 milliseconds before showing the toast, assuming the server will have responded by then.
D.Call the Apex method inside a try/catch, and show the success toast in the try block right after the invocation line without inspecting the resolved value.
AnswerA

Imperative Apex calls return a Promise, so .then() receives the resolved wrapper, letting the developer check the success Boolean before showing the success toast. .catch() receives server-side Apex exceptions, enabling a distinct error toast. This separation correctly distinguishes a business-level failure (success false) from a runtime exception, satisfying the requirement that the toast appears only when the save truly succeeded.

Why this answer

Imperative Apex calls return Promises, so the response must be consumed asynchronously. Reading the wrapper's success flag inside .then() ensures the toast only fires on a genuine success, while .catch() isolates server exceptions for an error toast. Showing the toast synchronously, using a wire adapter for a save, or relying on a fixed timeout all break the asynchronous contract and produce toasts that do not reflect the real outcome.

Exam trap

The trap here is treating the imperative Apex call as synchronous and showing the success toast on the line immediately after the invocation instead of inside the resolved Promise handler.

21
MCQeasy

A developer is creating a Lightning Web Component that will be placed on a Lightning record page for the Case object. The component must display the case's subject and status. Which approach correctly retrieves the record data so the component updates automatically when the record changes?

A.Use the lightning-record-form base component and read its output attributes to populate the display.
B.Call an Apex method from connectedCallback that queries the Case by Id and assign the result to a tracked property.
C.Import getRecord from lightning/uiRecordApi and wire it with the recordId property, then reference fields on the returned record.
D.Import getRecordNotifyChange and call it inside renderedCallback to fetch the latest field values.
AnswerC

The getRecord wire adapter from lightning/uiRecordApi subscribes to the Lightning Data Service record stream. When wired with @wire using the recordId, any record change made elsewhere on the page or by other components invalidates the cache and re-delivers data, so the component refreshes automatically. This is the documented pattern for displaying record fields reactively without writing Apex.

Why this answer

The getRecord wire adapter from lightning/uiRecordApi provides a reactive subscription to a single record through Lightning Data Service. Wiring it with the recordId property means the component receives updates whenever the record changes, satisfying the automatic refresh requirement. Apex calls, form components, and notify-change utilities do not provide this reactive single-record retrieval pattern.

Exam trap

The trap here is confusing getRecordNotifyChange, which only signals that data changed, with getRecord, which actually subscribes to and returns the record data.

22
MCQmedium

A developer is building a Lightning Web Component that needs to communicate with a parent component in a deep containment hierarchy. The event must traverse shadow boundaries without stopping at component boundaries. Which property configuration should the developer apply when instantiating the CustomEvent?

A.{ bubbles: true, composed: false }
B.{ bubbles: false, composed: true }
C.{ bubbles: true, composed: true }
D.{ cancelable: true, composed: false }
AnswerC

Setting `composed: true` allows the event to cross shadow DOM boundaries, while `bubbles: true` propagates it up through the containment hierarchy. Together they satisfy the stem's requirement that the event traverse shadow boundaries without stopping, reaching the parent component regardless of nesting depth.

Why this answer

Custom events in Lightning Web Components require the bubbles and composed properties to be set to true when they need to cross shadow DOM boundaries and propagate up through the entire DOM tree, including parent and grandparent components. Setting composed to false restricts the event strictly within the local shadow tree of the component that dispatched it.

Exam trap

Many developers assume that setting bubbles: true alone is sufficient for an event to reach a parent component across a shadow boundary, forgetting that composed must also be true.

23
MCQeasy

A developer needs a Lightning Web Component placed on a record page to read the 18-character id of the record currently being viewed, without querying the database or calling Apex. Which approach provides this value directly?

A.Declare a public property with @api recordId and reference it in the component.
B.Query the record id in Apex using ApexPages.currentPage().getParameters().
C.Call the getUserInfo wire adapter and read the currentRecordId field from the result.
D.Read the value from the page state by calling NavigationMixin.Navigate with a state object.
AnswerA

When a Lightning Web Component is placed on a record page, the platform automatically populates the @api recordId property with the id of the record being viewed. No query or Apex is needed. This is the documented, supported way to obtain the current record id in an LWC.

Why this answer

The platform injects the current record id into an @api property named recordId when an LWC is placed on a Lightning record page. This is the direct, no-Apex way to obtain the id. User info adapters, navigation state, and Visualforce page parameters do not supply the record id in this context.

Exam trap

The trap here is reaching for an Apex or Visualforce mechanism to read the record id, when the record page already injects it into an @api recordId property.

24
MCQmedium

A developer is building a Lightning Web Component for a Lightning Experience record page. The component must display a toast notification to the user after a successful save operation. The developer uses the ShowToastEvent from the lightning/platformShowToastEvent module. Which import statement is correct?

A.import { showToast } from 'lightning/platformShowToastEvent';
B.import ShowToastEvent from 'lightning/platformShowToastEvent';
C.import { ShowToastEvent } from 'lightning/platformShowToastEvent';
D.import { ShowToastEvent } from 'lightning/toastEvent';
AnswerC

This import correctly brings the ShowToastEvent class from the lightning/platformShowToastEvent module. In LWC, the module name is 'lightning/platformShowToastEvent' and the named export is ShowToastEvent. Using this import, the developer can create a new ShowToastEvent with parameters like title, message, and variant, then dispatch it via this.dispatchEvent. This is the standard way to show toast notifications in Lightning Experience.

Why this answer

The correct import statement is the one that uses the exact module name 'lightning/platformShowToastEvent' and the named export ShowToastEvent. This is the only valid way to import the toast event class in LWC. After importing, the developer instantiates the event with new ShowToastEvent({...}) and dispatches it.

The other options either use wrong export names, wrong import styles, or incorrect module paths, all of which would fail at build time.

Exam trap

The trap here is confusing the class name with a function name or using a default import when the module only provides named exports.

25
Multi-Selecthard

A developer is building a reusable Lightning Web Component that exposes public properties and methods to its parent, and needs to fire an event the parent can handle. Which TWO techniques are valid for this parent-child interaction? (Choose two.)

Select 2 answers
A.Use Lightning Message Service to publish a message the parent subscribes to, since LMS is required for any parent-child communication.
B.Store shared state on a window-level global variable so both parent and child can read and write it directly.
C.Annotate a property with @api so the parent can set it declaratively in markup or imperatively via the component instance.
D.Call the parent's method directly by querying the parent component with this.template.querySelector on the root element.
E.Dispatch a CustomEvent from the child and let the parent attach a handler with the on<eventname> attribute in its template.
AnswersC, E

@api is the decorator that makes a property or method part of the component's public API. A parent can set an @api property either declaratively as an attribute in the template or imperatively on the element reference in JavaScript. This is the documented mechanism for exposing data and behavior from a child to its parent, so it directly satisfies the reusable-component requirement.

Why this answer

Direct parent-child communication in LWC uses two complementary mechanisms: @api exposes properties and methods so a parent can pass data down or invoke a child method, and CustomEvent lets the child notify the parent upward, with the parent listening through the on<eventname> template attribute. Reaching into the parent from the child, using LMS for a direct parent-child relationship, or relying on global window state each violates the framework's encapsulation and reactivity model.

Exam trap

The trap here is believing Lightning Message Service is required for parent-child communication, when LMS is intended for communication across unrelated components or different DOM trees.

26
MCQeasy

A developer wants to ensure that a Lightning Web Component is only available for use on Record Pages for the Account and Contact objects in the Lightning App Builder. How should the developer configure the component's metadata file?

A.Define <target>lightning__RecordPage</target> and use <objects> in <targetConfig>.
B.Use the @isTest(SeeAllData=true) annotation in the JavaScript controller.
C.Add the objects to the 'scoped' attribute of the component's template tag.
D.Set the isExposed flag to false and list the objects in a custom property.
AnswerA

This configuration correctly identifies the Record Page as a valid target for the component. By further specifying the Account and Contact objects within the targetConfig section, the developer ensures that the component only appears in the App Builder palette when those specific record types are being edited.

Why this answer

The component's metadata file (.js-meta.xml) defines where and how a component can be used within the Salesforce UI. The 'target' tags specify the application context, while the 'targetConfigs' section allows for more granular control, such as restricting the component to specific objects. This ensures a better admin experience by preventing misplacement.

Exam trap

Candidates often try to use 'targets' alone without the 'targetConfigs' section, forgetting that targetConfigs are strictly required when you need to restrict a component to specific object types.

27
MCQmedium

A developer is building a Lightning Web Component that must surface a toast notification when an Apex callout returns a specific error code. The component is used inside a Salesforce mobile app and on desktop. Which module should the developer import to display the toast?

A.import { ToastEvent } from 'lightning/notifications';
B.import Toast from 'lightning/toast';
C.import { showToast } from 'lightning/uiRecordApi';
D.import { ShowToastEvent } from 'lightning/platformShowToastEvent';
AnswerD

Lightning Web Components display toasts by dispatching a ShowToastEvent, which is imported from the lightning/platformShowToastEvent module. This module is the standard, supported way to show a toast from an LWC, and it works consistently in Lightning Experience on desktop and in the Salesforce mobile app, which matches the cross-platform requirement in this scenario.

Why this answer

Toasts in Lightning Web Components are shown by dispatching a ShowToastEvent, which must be imported from the lightning/platformShowToastEvent module. This approach is the documented, cross-platform method supported in Lightning Experience and the Salesforce mobile app. The other modules either do not exist, serve unrelated purposes such as record data access or notifications, or would cause compilation errors.

Exam trap

The trap here is assuming a simpler toast API exists in a lightning/toast or lightning/notifications module, when the supported approach is ShowToastEvent from lightning/platformShowToastEvent.

28
MCQmedium

A developer is building a Lightning Web Component that includes a lightning-button. The button's click handler is defined as an arrow function in the component's JavaScript file. The developer wants to pass the event object to the handler to access the event's target. Which syntax should be used in the component's HTML template to correctly bind the handler and pass the event?

A.<lightning-button onclick={handleClick.bind(this)} label="Click"></lightning-button>
B.<lightning-button onclick={handleClick} label="Click"></lightning-button>
C.<lightning-button onclick={handleClick()} label="Click"></lightning-button>
D.<lightning-button onclick={handleClick(event)} label="Click"></lightning-button>
AnswerB

In Lightning Web Components, event handlers are bound using the onclick attribute without parentheses or the event object. The framework automatically passes the event as the first argument to the handler. The handler can then access event.target. This is the standard and correct syntax for binding a click handler in LWC.

Why this answer

The correct syntax is to use onclick={handleClick} without parentheses or the event object. Lightning Web Components automatically pass the event object to the handler when the event occurs. The handler can then access event.target and other properties.

The other options incorrectly attempt to invoke the function during template rendering or use unsupported syntax.

Exam trap

The trap here is assuming that you need to explicitly pass the event object or use parentheses, as in other frameworks like React or Vue.

29
MCQhard

A developer is creating a Lightning Web Component that must expose a public property so that a parent Aura component can pass a record ID into it. The LWC is embedded inside the Aura component using aura:component with an attribute. Which decorator and configuration should the developer use on the LWC property?

A.Decorate the property with @track and define a getter and setter in the LWC's .js file.
B.Decorate the property with @wire and import the record ID using lightning/uiRecordApi.
C.Define the property without any decorator and rely on the Aura component to set it via aura:attribute.
D.Decorate the property with @api and define it as a public property in the LWC's .js file.
AnswerD

@api exposes a property as public, allowing parent components—including Aura components—to set it via an attribute in markup or programmatically. When an Aura component nests an LWC, the attribute name maps to the public property. This is the documented way to pass data from Aura to LWC and is required for the record ID to be available in the child.

Why this answer

To allow an Aura parent to pass data into an LWC child, the LWC property must be part of its public API. The @api decorator makes a property public and settable from the parent's markup or JavaScript. When the Aura component uses an attribute with the same name, the framework maps it to the public property.

Without @api, the property remains private and the parent cannot set it.

Exam trap

The trap here is confusing reactivity decorators like @track with the public API decorator @api, when only @api exposes a property to a parent component.

30
MCQmedium

A developer is building a complex nested Lightning Web Component structure. A deeply nested child component needs to notify an ancestor component, which is not the immediate parent, about a data change. Which configuration of the CustomEvent constructor should the developer use to ensure the event reaches the ancestor across the shadow DOM boundary?

A.new CustomEvent('update', { bubbles: true, composed: false });
B.new CustomEvent('update', { bubbles: false, composed: true });
C.new CustomEvent('update', { bubbles: true, composed: true });
D.new CustomEvent('update', { detail: { bubbles: true, composed: true } });
AnswerC

Combining bubbles and composed properties ensures the event travels up the DOM and successfully exits the shadow DOM boundary. This is the standard approach for bubbling events to ancestors that are not direct parents, allowing the event to reach the document root or any listener registered on higher-level components.

Why this answer

Understanding event propagation in Lightning Web Components is vital for building scalable architectures. When an event needs to cross the shadow DOM boundary and continue bubbling up the regular DOM, both the bubbles and composed properties must be set to true. This allows the event to reach components outside of the immediate shadow root where it originated, enabling decoupled communication between distant components.

Exam trap

Candidates often set only 'bubbles: true' and forget 'composed: true'. Without both, the event will stop at the shadow DOM boundary and never reach the ancestor component.

31
MCQhard

A developer is building a Lightning Web Component that contains an iframe hosting an external web application. The external application needs to send a message back to the Lightning Web Component when a user completes a task. Which mechanism should the developer use to receive that message securely?

A.Register a Lightning Message Service message channel and subscribe to it from the component; the iframe publishes to the same channel.
B.Use the Lightning Web Component's @api property to bind directly to a variable exposed by the iframe's document object.
C.Poll the iframe element's contentWindow property on an interval and read a status variable set by the external application.
D.Add a window message event listener in the component and validate the event origin against the expected external domain before processing the payload.
AnswerD

The browser's postMessage API is the standard way for an iframe and its host to exchange data across origins. Listening for the message event on window and verifying event.origin against the trusted external domain prevents malicious pages from injecting forged messages. This is the secure, supported pattern for cross-origin communication with an embedded external application.

Why this answer

Cross-origin communication with an embedded external application is handled through the browser's postMessage API. The component adds a window message listener and validates event.origin against the trusted domain before acting on the payload. Lightning Message Service, @api properties, and polling contentWindow cannot bridge the same-origin boundary that isolates the external iframe.

Exam trap

The trap here is assuming that Salesforce messaging features such as Lightning Message Service extend into third-party iframes, when browser cross-origin rules require the postMessage API instead.

32
MCQhard

A developer needs a Lightning Web Component to expose a public method so that an Aura component on the same page can call it and pass a string parameter. Which approach should the developer use?

A.Use Lightning Message Service to publish a message that the Aura component subscribes to.
B.Declare the method inside a wire adapter in the LWC.
C.Define the method as a static method on the LWC class.
D.Define a public method in the LWC and annotate it with @api.
AnswerD

In Lightning Web Components, public properties and methods are exposed by decorating them with @api. When an Aura component contains an LWC, the Aura component can call the LWC's public method through the element reference. This is the documented interop pattern for Aura-to-LWC communication, so annotating the method with @api is the correct approach.

Why this answer

Lightning Web Components expose public methods to parent Aura components by decorating them with @api. The Aura component can then call the method on the LWC element reference. Other options either do not provide a callable instance method, use asynchronous messaging that lacks return values, or confuse data provisioning with method exposure, so they do not meet the requirement.

Exam trap

The trap here is assuming that Lightning Message Service or a wire adapter can be used for direct method invocation, when only an @api-decorated method is callable from the parent Aura component.

33
MCQeasy

A developer needs to display a read-only, formatted phone number on a Lightning record page. The value comes from a field on the record and should render consistently with Salesforce's standard phone formatting. Which base component should be used?

A.lightning-formatted-phone
B.lightning-output-field
C.lightning-formatted-number
D.lightning-formatted-text
AnswerA

lightning-formatted-phone is purpose-built to display phone numbers with standard formatting and renders the value as a clickable tel link. It accepts a value attribute and applies consistent presentation, which is exactly what the scenario requires for a read-only formatted phone number on a record page.

Why this answer

lightning-formatted-phone is the base component specifically designed to render phone numbers with standard formatting and a clickable tel link. Other formatted components target different data types, and lightning-output-field depends on a record form context. For a standalone, consistently formatted phone display, the phone-specific component is the correct choice.

Exam trap

The trap here is selecting a general-purpose formatter like formatted-text or formatted-number when a type-specific component exists for phone values.

34
MCQmedium

A developer is building a Lightning Web Component that must navigate the user to a new record's detail page after a successful Apex DML operation. Which module should the developer use to perform the navigation?

A.import { NavigationMixin } from 'lightning/navigation';
B.import { navigate } from 'lightning/platformNavigation';
C.Use the window.location.assign method with a relative URL.
D.Dispatch a custom event named 'navigate' that the parent component handles.
AnswerA

The lightning/navigation module provides NavigationMixin, which enables Lightning Web Components to navigate to various page types such as record pages, list views, and named pages. By mixing NavigationMixin into the component class and calling this[NavigationMixin.Navigate] with the appropriate page reference, the developer can redirect the user after the DML operation completes.

Why this answer

Lightning Web Components navigate using NavigationMixin from the lightning/navigation module. After a successful DML operation, the component can use NavigationMixin.Navigate with a standard__recordPage page reference to redirect the user. Other options either reference non-existent modules, bypass the Lightning navigation framework with a full page reload, or rely on custom events that are not part of the platform navigation API.

Exam trap

The trap here is confusing standard browser navigation or custom events with the platform navigation service, when NavigationMixin is the supported approach in LWC.

35
MCQmedium

A developer is building a Lightning Web Component that needs to display a formatted date and time based on the user's timezone. Which standard JavaScript object, compatible with LWC, should be used to handle this without additional libraries?

A.Intl.DateTimeFormat
B.Moment.js
C.Date.toGMTString()
D.System.now().format()
AnswerA

Intl.DateTimeFormat is a standard JavaScript constructor that enables locale-aware date and time formatting. It is fully supported in LWC and allows developers to pass options such as 'timeZone' and 'locale' to produce strings that are correctly formatted for the user's specific regional settings.

Why this answer

Modern browsers and the LWC environment support the Internationalization API (Intl). This built-in JavaScript object provides robust capabilities for formatting dates, numbers, and currencies according to specific locales and timezones. Using standard APIs is preferred over third-party libraries for better performance and reduced bundle size.

Exam trap

Candidates frequently select third-party JavaScript libraries or server-side Apex methods, overlooking the built-in browser support for the native Internationalization API.

36
MCQmedium

A developer is building a Lightning Web Component that renders a custom list of navigation links. The component must follow the Salesforce Lightning Design System (SLDS) styling and remain accessible to screen readers. Which approach best satisfies both the styling and accessibility requirements?

A.Use lightning-button components for each link and set the variant attribute to base for all of them.
B.Apply SLDS utility classes to standard anchor elements and add appropriate ARIA attributes such as aria-current for the active link.
C.Create custom CSS that mimics SLDS colors and typography, and omit ARIA attributes because the visual design is sufficient.
D.Use div elements with onclick handlers and SLDS classes, and add role="link" to each div.
AnswerB

Using SLDS utility classes on semantic anchor elements gives the visual styling the design system defines while preserving native link semantics that assistive technology understands. Adding aria-current marks the active item so screen readers announce it correctly. This combination keeps markup semantic, follows SLDS conventions, and meets the accessibility requirement without custom CSS or non-semantic elements.

Why this answer

Semantic anchor elements styled with SLDS utility classes satisfy both the visual and accessibility requirements. Native links are keyboard accessible and understood by screen readers, and adding aria-current identifies the active item. Non-semantic divs, custom CSS, or button components either break semantics or duplicate the design system without addressing accessibility.

Exam trap

The trap here is treating visual similarity as sufficient, when replacing native links with styled divs or buttons silently removes keyboard and screen reader semantics.

37
MCQeasy

A developer is creating a Lightning Web Component that needs to display a toast message when a record is saved successfully. The developer imports ShowToastEvent from lightning/platformShowToastEvent. Which code correctly dispatches a success toast with the title 'Saved' and message 'Record saved successfully'?

A.ShowToastEvent.dispatch(this, { title: 'Saved', message: 'Record saved successfully', variant: 'success' });
B.this.dispatchEvent(new ShowToastEvent({ title: 'Saved', message: 'Record saved successfully', variant: 'success' }));
C.this.dispatchEvent(new ShowToastEvent({ title: 'Saved', message: 'Record saved successfully' }));
D.this.dispatchEvent(new ShowToastEvent('Saved', 'Record saved successfully', 'success'));
AnswerB

This code correctly creates a new ShowToastEvent with the required parameters: title, message, and variant. The variant 'success' displays a green success toast. Dispatching the event on the component instance using this.dispatchEvent is the standard way to show a toast in LWC. This is the correct and complete syntax.

Why this answer

The correct code creates a new ShowToastEvent with an object containing title, message, and variant set to 'success', then dispatches it using this.dispatchEvent. This displays a success toast. The other options either use incorrect syntax, omit the variant, or attempt to call a non-existent static method.

Exam trap

The trap here is forgetting to include the variant property, which changes the toast's appearance and semantic meaning.

38
MCQmedium

A developer is building a Lightning Web Component that must expose a public method so a parent component can programmatically trigger a refresh of the child's data. The child component's method is decorated with @api and named refreshData. The parent component holds a template reference to the child element. Which code in the parent correctly invokes the child method?

A.this.dispatchEvent(new CustomEvent('refreshData'));
B.this.template.querySelector('c-child').call('refreshData');
C.this.template.querySelector('c-child').refreshData();
D.this.template.querySelector('c-child').refreshData;
AnswerC

A template reference obtained with querySelector returns the child custom element, and public methods decorated with @api are exposed directly on that element instance. Calling refreshData() on it invokes the child's public method. This is the documented pattern for parent-to-child imperative communication in Lightning Web Components when no reactive property change is involved.

Why this answer

Public methods on a Lightning Web Component are declared with @api and become callable JavaScript methods on the element instance. A parent obtains the child element through a template query and invokes the method directly. Custom events, aura-style call() helpers, and bare method references do not perform an imperative parent-to-child invocation.

Exam trap

The trap here is assuming Lightning Web Components use the Aura cmp.get('c.method') invocation style, when @api methods are simply called as normal JavaScript functions on the element.

39
MCQhard

A developer is creating a Lightning Web Component that includes a lightning-input field for a phone number. The component must validate that the input matches a specific pattern before allowing the user to submit a form. The developer wants to use the built-in validation features of lightning-input. Which attribute should be set to enforce a custom validation pattern?

A.validation
B.regex
C.validity
D.pattern
AnswerD

The pattern attribute on lightning-input accepts a regular expression string that the input value must match. When the form is submitted, the browser's native constraint validation API checks the value against the pattern. If it does not match, the input is marked invalid and the form submission is blocked. This provides a simple way to enforce custom validation without writing extra JavaScript. The pattern attribute works with the standard HTML pattern attribute semantics.

Why this answer

The pattern attribute is the correct choice because it allows the developer to specify a regular expression that the input value must match. When the form is submitted, the browser's constraint validation API checks the input against this pattern and prevents submission if it fails. The other attribute names do not exist on lightning-input.

Using pattern is the standard, declarative way to add custom validation to a lightning-input field without writing additional JavaScript.

Exam trap

The trap here is assuming that a custom attribute like regex or validation exists for pattern matching, when the component actually follows the standard HTML pattern attribute.

Ready to test yourself?

Try a timed practice session using only User Interface questions.