Courseiva

CCNA User Interface Questions

16 of 91 questions · Page 2/2 · User Interface topic · Answers revealed

76
Multi-Selecthard

Which THREE strategies are recommended for improving the performance of Lightning Web Components rendering large lists of data? Choose 3 answers.

Select 3 answers
A.Use synchronous imperative Apex calls inside template iterators.
B.Provide a unique, stable 'key' attribute (such as record Id) on each iterated element in for:each loops.
C.Implement pagination or virtual scrolling / lazy loading for large datasets.
D.Avoid heavy computations inside template getter properties called during renders.
E.Render all 10,000 records at once in a single flat DOM tree without pagination.
AnswersB, C, D

Providing a unique, stable `key` attribute on each iterated element directly satisfies the requirement for rendering large lists of data efficiently. The Lightning Web Components framework relies on the `key` value within `for:each` directives to uniquely identify DOM nodes during the virtual DOM reconciliation process. When the underlying array updates, the diffing algorithm uses these stable keys to track item insertions, deletions, and reordering accurately. This mechanism prevents the browser from having to needlessly destroy and recreate entire DOM subtrees, thereby optimising rendering performance and preserving internal component state.

Why this answer

Option B is correct because giving each iterated element a unique, stable key (e.g., the record Id) in for:each loops lets the Lightning Web Components engine's diffing algorithm track items across re-renders and reuse DOM nodes instead of destroying and recreating them, which dramatically reduces rendering work. Option C is correct because pagination, virtual scrolling, or lazy loading limits the number of rows actually rendered in the DOM at any time, so the browser only paints a small window of records rather than the entire dataset, keeping render and layout times low. Option D is correct because getter properties referenced in a template are re-evaluated on every render cycle, so placing heavy computation or data transformation there multiplies the cost across all rows; moving that logic to one-time initialization or cached properties avoids repeated expensive work.

Option A is not recommended because synchronous imperative Apex calls block the client thread and, when invoked inside iterators, can fire one call per row, causing severe latency and governor-limit pressure. Option E is incorrect because rendering all 10,000 records at once in a single flat DOM tree creates an enormous DOM, causing slow initial render, sluggish scrolling, and high memory usage, which is exactly the anti-pattern these strategies are meant to avoid.

Exam trap

The trap is selecting options that seem intuitive but actually harm performance, such as rendering all records at once or using synchronous calls in loops; candidates may not realize the impact on rendering.

77
MCQhard

A developer is working with a Lightning Web Component and needs to ensure reactive updates occur when an object property or array element changes inside a tracked property. What is the correct approach in modern LWC?

A.Reassign the property reference (e.g., this.myObj = {...this.myObj}).
B.Use @track on every inner property.
C.Call component.forceUpdate().
D.Mutate the nested property directly; LWC automatically deep-tracks all mutations.
AnswerA

Lightning Web Components use a shallow reactivity track for properties decorated with `@track`. When mutating nested properties of an object or elements within an array, the framework does not automatically detect deep mutations because observing every nested level would degrade runtime performance. Reassigning the entire object reference forces the component's reactive engine to evaluate the change and trigger a re-render, directly satisfying the requirement for reactive updates when internal properties of a tracked object or array shift.

Why this answer

Assigning a new object or array reference (mutation via replacement) triggers reactivity in LWC tracked properties.

78
MCQhard

A developer is implementing a Lightning Web Component that handles drag-and-drop functionality. Which native DOM event is typically intercepted to allow a drop action on an element?

A.dragstart
B.dropstart
C.dragover and preventDefault()
D.mousedown
AnswerC

To successfully implement a drag-and-drop workflow within a Lightning Web Component, developers must intercept the native `dragover` DOM event. By default, browsers prevent elements from acting as valid drop targets. Calling `preventDefault()` within a `dragover` event handler overrides this browser restriction, satisfying the stem's requirement to explicitly permit a drop action on a specific element.

Why this answer

To allow a drop on an element, the developer must intercept the 'dragover' event and call preventDefault() on it. By default, browsers do not allow dropping on an element; calling preventDefault() in the dragover handler signals that the element is a valid drop target, after which the 'drop' event fires. This is the standard HTML5 drag-and-drop contract.

Exam trap

Salesforce-PD1 often tests the HTML5 drag-and-drop contract — the trap is picking 'dragstart' (the source event) instead of 'dragover' + preventDefault() (the target-side requirement to enable dropping).

How to eliminate wrong answers

Option A is wrong because 'dragstart' fires on the source element when the drag begins, not on the drop target, and it does not enable dropping. Option B is wrong because 'dropstart' is not a native DOM event — it is a fabricated name that does not exist in the HTML5 drag-and-drop API. Option D is wrong because 'mousedown' is a pointer event unrelated to drag-and-drop; it fires when a mouse button is pressed but does not participate in the drag lifecycle.

79
MCQhard

A developer is writing an Aura component and needs to dynamically create a component at runtime. Which JavaScript method should be used?

A.document.createElement()
B.$A.createComponent()
C.Aura.create()
D.component.new()
AnswerB

Dynamic component instantiation in Aura requires `$A.createComponent()`, which directly satisfies the requirement to create components programmatically at runtime rather than declaratively in markup. This asynchronous framework method accepts the component descriptor, attribute definitions, and a callback function that handles the newly instantiated component once it is successfully created in memory. By executing this method within a controller or helper, developers can construct complex user interfaces dynamically based on user interaction or conditional logic.

Why this answer

$A.createComponent() is the Aura framework's factory method for dynamically instantiating a component at runtime by name, returning a callback with the new component instance that can then be inserted into the DOM via component.set('v.body', ...). It is the only supported way to create Aura components programmatically rather than declaratively in markup.

Exam trap

The trap is confusing native DOM creation (document.createElement) or made-up framework methods with the actual Aura factory API — candidates who haven't written dynamic Aura code often guess at a plausible-sounding method name instead of recalling $A.createComponent().

How to eliminate wrong answers

Option A is wrong because document.createElement() is a native DOM API that creates plain HTML elements, not Aura components — it bypasses the Aura framework entirely and cannot instantiate a component with its own controller, renderer, or attributes. Option C is wrong because Aura.create() is not a real API; the Aura namespace does not expose a create() method for component instantiation. Option D is wrong because component.new() does not exist — components are created through the $A global's createComponent() (or createComponents() for multiple), not through an instance method on an existing component.

80
MCQhard

A developer needs to access a specific HTML element in a Lightning Web Component template imperatively. Which method should be called?

A.window.findElement()
B.this.template.querySelector()
C.this.findElement()
D.document.querySelector()
AnswerB

Shadow DOM encapsulation in Lightning Web Components restricts direct global DOM access, requiring scoped traversal to locate elements. The `this.template.querySelector()` method satisfies the requirement to access a specific HTML element imperatively from within the component's JavaScript controller by searching solely within the component's own template template-bound boundary. This approach ensures compliance with Lightning security and encapsulation paradigms, allowing developers to query and manipulate targeted DOM nodes reliably without breaking component isolation rules.

Why this answer

In Lightning Web Components, to access an element in the template imperatively, you must use this.template.querySelector() with a CSS selector. This method scopes the query to the component's template, ensuring encapsulation and preventing access to elements outside the component. It returns the first matching element.

Exam trap

SALESFORCE-PD1 often tests the correct method for DOM access in LWC, and candidates may mistakenly use document.querySelector() due to familiarity with standard web development, ignoring LWC's encapsulation.

How to eliminate wrong answers

Option A is wrong because window.findElement() is not a standard method and does not exist in the DOM API. Option C is wrong because this.findElement() is not a method provided by the LightningElement base class. Option D is wrong because document.querySelector() queries the entire document, which breaks component encapsulation and may return elements outside the component, leading to unpredictable behavior and potential security issues.

81
MCQmedium

A developer is writing a Visualforce page that uses a custom controller. The page needs to execute an action method as soon as the page loads, without requiring user interaction. Which attribute on <apex:page> should be used?

A.initMethod="{!init}"
B.action="{!init}"
C.onLoad="{!init}"
D.loadAction="{!init}"
AnswerB

The `action` attribute on the `<apex:page>` component evaluates a controller method when the page is requested, fulfilling the requirement to execute logic immediately upon loading without user intervention. By binding this attribute to a controller method expression such as `{!init}`, the Salesforce platform automatically invokes the specified server-side code during the initial HTTP request lifecycle. This mechanism ensures the necessary initialisation occurs before the markup is rendered to the client browser.

Why this answer

The `action` attribute on `<apex:page>` specifies a controller method that is executed when the page loads, before rendering, without user interaction. It is the standard Visualforce mechanism for initialization logic, such as loading data or setting up state. The correct syntax is `action="{!init}"`, where `init` is a public method in the custom controller.

Exam trap

Salesforce-PD1 often tests the confusion between `action` and non-existent attributes like `initMethod` or `onLoad` — candidates pick the most descriptive-sounding name instead of the actual Visualforce attribute.

How to eliminate wrong answers

Option A is wrong because `initMethod` is not a valid attribute on `<apex:page>`; it does not exist in the Visualforce component reference. Option C is wrong because `onLoad` is not a valid `<apex:page>` attribute — `onload` exists as a JavaScript event attribute in some contexts, but not as a controller action binding on `<apex:page>`. Option D is wrong because `loadAction` is not a recognized Visualforce attribute; it is a fabricated name that resembles `action` but has no effect.

82
MCQhard

A developer is creating a Lightning Web Component that needs to conditionally render a section based on a boolean property. The property is initially false and is set to true after data is loaded from an Apex method. Which approach should the developer use to ensure the section renders only when the property is true?

A.Use the if:true directive on the section element.
B.Use a JavaScript querySelector to add or remove the section element from the DOM.
C.Use a CSS class with display: none and toggle it based on the property.
D.Use the rendered attribute on the section element.
AnswerA

The if:true directive conditionally renders the element and its children only when the bound expression evaluates to true. In this scenario, when the boolean property becomes true after data load, the section will render. This is the standard declarative way to conditionally render content in Lightning Web Components.

Why this answer

Conditional rendering in Lightning Web Components is done using if:true or if:false directives. These directives add or remove elements from the DOM based on the truthiness of the bound expression. When the boolean property changes to true, the section is rendered.

This approach is efficient and aligns with the framework's reactive model.

Exam trap

The trap here is confusing Aura's rendered attribute with LWC's if:true directive, or resorting to CSS hiding, which does not actually remove elements from the DOM.

83
MCQmedium

A developer is working with a Lightning Web Component that uses the @wire decorator to provision data from an Apex method. The Apex method depends on a property that changes dynamically. How should the property be prefixed to signal reactivity to the wire service?

A.Enclose the property name in curly braces ({})
B.Prefix the property name with a dollar sign ($)
C.Prefix the property name with an ampersand (&)
D.Prefix the property name with an underscore (_)
AnswerB

The dollar-sign prefix marks a property as reactive, so the wire service re-invokes the Apex method whenever that property's value changes. Without it, the wire adapter provisions data only once, ignoring the dynamic dependency described in the stem.

Why this answer

In Lightning Web Components, the @wire decorator uses a reactive variable syntax where a property prefixed with a dollar sign ($) is treated as a dynamic parameter. When that property changes, the wire service automatically re-invokes the Apex method with the new value. This is the documented LWC reactive wire pattern, e.g., @wire(getContact, { contactId: '$recordId' }).

Exam trap

Salesforce-PD1 often tests the distinction between Aura's {!v.property} expression syntax and LWC's '$property' reactive wire syntax, causing candidates who recently studied Aura to select the curly-brace option.

How to eliminate wrong answers

Option A is wrong because curly braces ({}) are the Aura component expression syntax (e.g., {!v.recordId}), not the LWC wire reactivity marker — LWC templates use {property} for rendering, but the wire adapter specifically requires the $ prefix. Option C is wrong because the ampersand (&) has no special meaning in LWC wire parameter binding; it is not a reactivity sigil in any Salesforce UI framework. Option D is wrong because an underscore prefix is a JavaScript naming convention for private/internal members and carries no semantic meaning to the wire service.

84
MCQhard

A developer is implementing a custom pagination mechanism in a Lightning Web Component. The component uses an Apex controller method that returns a list of records. Which technique prevents excessive heap size and improves performance when dealing with large datasets?

A.Fetch all records in a single transaction and slice the array in JavaScript.
B.Store the entire dataset in browser local storage for client-side manipulation.
C.Use the @wire decorator with an unbounded query and enable auto-caching.
D.Use server-side pagination passing page offset and limit parameters to the Apex controller.
AnswerD

Passing page offset and limit parameters directly to the Apex controller ensures that only the specific subset of records required for the current view is queried and transferred, satisfying the requirement to prevent excessive heap size and improve performance when dealing with large datasets. By leveraging SOQL `LIMIT` and `OFFSET` clauses, the server-side code avoids loading thousands of unnecessary records into memory, thereby respecting Salesforce governor limits and drastically reducing payload size over the network.

Why this answer

Implementing server-side pagination with OFFSET and LIMIT or using standard database query locators in Apex is best practice.

85
Multi-Selecthard

Which THREE practices are considered security best practices when developing custom Visualforce pages to prevent Cross-Site Scripting (XSS)? Choose 3 answers.

Select 3 answers
A.Use standard Visualforce components like <apex:outputText> which automatically HTML-escape output by default.
B.Disable sharing on all controller classes.
C.Set escape="false" on all output components to ensure proper rendering.
D.Use String.escapeJavaScript() when rendering user input inside JavaScript contexts.
E.Encode untrusted user input using JSENCODE or HTMLENCODE helper functions.
AnswersA, D, E

Standard Visualforce components such as `<apex:outputText>` provide an automatic HTML-escaping mechanism that neutralises malicious scripts before rendering data in the browser. This directly satisfies the requirement to prevent Cross-Site Scripting (XSS) vulnerabilities by ensuring that user-supplied input or dynamic field values containing executable JavaScript cannot be interpreted as code by the Document Object Model. By default, these built-in components encode characters like `<` and `>` into their safe entity equivalents, mitigating injection risks without requiring manual developer intervention.

Why this answer

Preventing XSS in Visualforce involves escaping output, using standard components which escape by default, and encoding untrusted data.

86
MCQeasy

A developer needs to ensure that a Lightning Web Component can be placed on a Record Page for an Account in the Lightning App Builder. What must be configured in the component's metadata configuration file?

A.<target>lightning__HomePage</target>
B.<target>lightning__RecordPage</target>
C.<target>lightning__Tab</target>
D.<target>lightningCommunity__Default</target>
AnswerB

Including the `lightning__RecordPage` target within the `targets` array of the component’s metadata file explicitly enables the component to be surfaced within the Lightning App Builder for record-specific pages. This configuration satisfies the requirement to place the component on an Account Record Page by registering the component’s availability for the record page context. Without this specific target declaration, the Lightning App Builder will not display the component in the custom components list, thereby preventing its deployment to the desired user interface.

Why this answer

The target configuration must include lightning__RecordPage and specify the appropriate object support.

87
MCQhard

A developer has an Aura component that needs to communicate with an unrelated Lightning Web Component located on the same Lightning page. Which feature should the developer implement?

A.Lightning Message Service (LMS)
B.Aura Component Events (app events)
C.A shared JavaScript closure via window globals
D.Direct DOM traversal using document.querySelector()
AnswerA

Lightning Message Service provides a standardised publish-subscribe mechanism that enables communication across the DOM, effectively bridging the gap between Aura components and Lightning Web Components. By utilising a MessageChannel, developers can facilitate decoupled interaction between components that do not share a common parent. This approach satisfies the constraint of the components being unrelated, as it bypasses the limitations of traditional parent-child event propagation, ensuring seamless data exchange regardless of the component hierarchy or the specific framework used within the Lightning page.

Why this answer

The Lightning Message Service (LMS) allows communication between Visualforce pages, Aura components, and Lightning Web Components across the DOM.

88
MCQmedium

A developer is building a Lightning Web Component that displays a list of contacts for a selected account. The component must call an Apex method that returns contacts, and the developer wants to handle the result using a Promise chain. Which Apex method annotation is required to expose the method to the Lightning Web Component?

A.@HttpGet
B.@AuraEnabled(cacheable=true)
C.@RemoteAction
D.@InvocableMethod
AnswerB

This annotation makes the Apex method available to Lightning Web Components via the wire service and imperative calls. It also enables client-side caching, which improves performance. Without it, the method cannot be called from the component, so it is the correct choice for exposing server-side logic to LWC.

Why this answer

Lightning Web Components communicate with Apex via methods annotated with @AuraEnabled. The annotation can include cacheable=true to enable client-side caching, which is beneficial for read-only operations. Without @AuraEnabled, the Apex method is not exposed to the component, and the import statement would fail.

Therefore, the correct annotation is @AuraEnabled(cacheable=true).

Exam trap

The trap here is confusing @AuraEnabled with other Apex annotations like @RemoteAction or @InvocableMethod, which serve different integration purposes and are not used for direct LWC-to-Apex calls.

89
MCQmedium

A developer is building a Lightning Web Component that includes user input fields. To adhere to best practices for accessibility and SLDS form styling, how should form inputs be structured?

A.Use standard HTML inputs without associated label elements.
B.Use <table> tags for layout alignment of form fields.
C.Use SLDS form element containers with corresponding <lightning-input> or HTML input elements paired with explicit labels.
D.Apply inline CSS display:flex directly to raw text areas.
AnswerC

Pairing each input with an explicit label satisfies the accessibility requirement, since SLDS form element containers expect a label element bound to the input's id. Using `<lightning-input>` supplies that association automatically, while raw HTML inputs need a matching `for` attribute, meeting the stem's SLDS styling and accessibility constraints.

Why this answer

SLDS provides form element containers (slds-form-element, slds-form-element__label, slds-form-element__control) that pair labels with inputs for correct spacing, alignment, and screen-reader association. Using lightning-input (which renders SLDS-compliant markup with built-in label support) or native HTML inputs wrapped in these SLDS containers with explicit <label for> associations satisfies both accessibility and styling best practices.

Exam trap

The trap is treating form layout as a pure visual concern — candidates pick table-based or inline-CSS options because they 'look' like they align fields, ignoring that SLDS containers and explicit label association are required for both accessibility compliance and consistent Lightning styling.

How to eliminate wrong answers

Option A is wrong because inputs without associated label elements fail WCAG accessibility requirements — screen readers cannot announce the field's purpose, and SLDS styling for labels is bypassed. Option B is wrong because using <table> tags for layout is a deprecated, non-responsive technique that breaks SLDS grid conventions and harms accessibility since tables imply tabular data relationships to assistive technology. Option D is wrong because applying inline display:flex to raw text areas bypasses SLDS design tokens, breaks consistent theming, and does not address label association or accessibility at all.

90
MCQeasy

A developer is building a Lightning Web Component and needs to execute code as soon as the component is inserted into the DOM. Which lifecycle hook should be used?

A.renderedCallback
B.constructor
C.connectedCallback
D.disconnectedCallback
AnswerC

The `connectedCallback` lifecycle hook executes automatically when a component is inserted into the DOM, satisfying the requirement to trigger code immediately upon mounting. Unlike the `constructor` which runs before the component is connected, this hook provides access to the element's properties and the DOM environment. It serves as the standard entry point for initialising data or performing setup tasks, ensuring that the component is fully integrated into the page structure before the logic begins to execute.

Why this answer

The connectedCallback lifecycle hook is called when a component is inserted into the DOM. It is the appropriate place to execute initialization code that requires the component to be in the document, such as accessing the DOM or making imperative Apex calls.

Exam trap

Salesforce PD1 often tests the distinction between connectedCallback and renderedCallback; candidates may confuse the two, thinking renderedCallback is for initial insertion, but it actually runs after every render.

How to eliminate wrong answers

Option A is wrong because renderedCallback is called after the component is rendered, which occurs after connectedCallback; it is used for post-render logic, not initial insertion. Option B is wrong because the constructor is called before the component is inserted into the DOM; it is used for initializing state but cannot access the DOM or perform certain operations. Option D is wrong because disconnectedCallback is called when the component is removed from the DOM, not when inserted.

91
Multi-Selectmedium

A developer is creating an Aura component that interacts with Salesforce data. Which TWO tags or features are valid in the Aura framework? (Choose TWO)

Select 2 answers
A.<aura:iteration items="{!v.items}" var="item">
B.<template for:each={items} for:item="item">
C.<aura:attribute name="myAttr" type="String" />
D.<lwc:databind property="{!v.val}" />
E.import { LightningElement } from 'lwc';
AnswersA, C

The `<aura:iteration>` tag acts as the primary mechanism for rendering collections within the Aura framework, satisfying the requirement to interact with Salesforce data by dynamically iterating over an array of records. By binding the `items` attribute to a controller-provided list, developers can efficiently generate repetitive UI elements based on server-side data. This tag is essential for data-driven components, as it handles the transformation of complex object collections into individual component instances without requiring manual DOM manipulation or external libraries.

Why this answer

Option A is correct because <aura:iteration> is a core Aura framework tag used to iterate over a collection such as v.items, rendering the body once per element with the specified var attribute. Option C is correct because <aura:attribute> is the standard Aura tag for declaring a component attribute, with name and type (e.g., String) being valid attributes. Option B is not valid Aura syntax; for:each and for:item are Lightning Web Components template directives, not Aura tags.

Option D is not valid; lwc:databind is not an Aura or LWC feature, and Aura uses {!v.val} expressions without such a tag. Option E is not valid in an Aura component because import { LightningElement } from 'lwc' is the LWC base class import, used in JavaScript files of Lightning Web Components, not Aura.

Exam trap

The trap here is mixing Aura and LWC syntax in the same question — candidates who have studied both frameworks may incorrectly select LWC constructs (for:each, LightningElement import) as valid Aura features.

← PreviousPage 2 of 2 · 91 questions total

Ready to test yourself?

Try a timed practice session using only User Interface questions.