Praxis Academy
Home › Platform Developer II › User Interface

Platform Developer II practice questions: User Interface

User Interface is 20% of the Salesforce Certified Platform Developer II exam. It covers LWC lifecycle, wire service, Lightning Data Service, Message Service, Visualforce controllers. Try these 15 free questions, then open each answer to see why every option is right or wrong.

01

A logistics company builds an LWC for the Shipment__c record page. It must call an imperative Apex method that needs the recordId as soon as the component is inserted into the DOM. Where should the developer place the call?

  1. In the constructor(), right after calling super()
  2. In connectedCallback(), which runs when the component is inserted into the DOM
  3. In renderedCallback(), guarded by no additional logic
  4. In disconnectedCallback(), so the call completes before rendering
Show answer

Answer: B

A. In the constructor(), right after calling super()Public properties such as recordId are not yet set by the owner when the constructor runs, so the value would be undefined.
B. In connectedCallback(), which runs when the component is inserted into the DOM ✓Correct. connectedCallback() fires after public properties are set and the component is inserted, making it the standard place for initial data loading.
C. In renderedCallback(), guarded by no additional logicrenderedCallback() runs after every render, so an unguarded Apex call there would execute repeatedly.
D. In disconnectedCallback(), so the call completes before renderingdisconnectedCallback() runs when the component is removed from the DOM, not when it is inserted.

Why: connectedCallback() is the lifecycle hook for one-time initialization that depends on public properties, such as calling Apex or subscribing to a message channel. The constructor runs too early to read values passed in by the owner.

02

A healthcare LWC on the Patient__c record page wires an Apex method: @wire(getAppointments, { patientId: ??? }) appointments; The list must reload automatically if recordId changes. What should replace ????

  1. this.recordId
  2. '$recordId'
  3. {recordId}
  4. '@api recordId'
Show answer

Answer: B

A. this.recordIdReferencing this.recordId passes the value once at class definition time and is not reactive in a wire configuration.
B. '$recordId' ✓Correct. Prefixing the property name with $ inside a string makes the parameter reactive, so the wire reprovisions when recordId changes.
C. {recordId}Curly-brace binding is template syntax and is not valid inside the wire configuration object.
D. '@api recordId'Decorators cannot be referenced inside a wire parameter string; the value would be passed literally.

Why: In a @wire configuration, a string value starting with $ refers to a property of the component and makes the wire reactive. When that property changes, the wire service fetches new data.

03

A property management LWC shows a Unit__c record with getRecord. A button calls an imperative Apex method that updates the Status__c of that record. The displayed status stays stale. What should the developer call after Apex completes?

  1. notifyRecordUpdateAvailable([{ recordId: this.recordId }]) from lightning/uiRecordApi
  2. refreshApex(this.recordId)
  3. location.reload() to reload the Lightning page
  4. this.dispatchEvent(new CustomEvent('refresh'))
Show answer

Answer: A

A. notifyRecordUpdateAvailable([{ recordId: this.recordId }]) from lightning/uiRecordApi ✓Correct. notifyRecordUpdateAvailable() tells Lightning Data Service the record changed outside LDS, so wires using getRecord receive fresh data.
B. refreshApex(this.recordId)refreshApex() refreshes data provisioned by a wired Apex method, and it takes the provisioned value, not a record Id.
C. location.reload() to reload the Lightning pageReloading the whole page works but discards state and is not the recommended way to sync the LDS cache.
D. this.dispatchEvent(new CustomEvent('refresh'))A custom event only notifies a parent component; it does not update the Lightning Data Service cache.

Why: When records are changed by Apex or another non-LDS mechanism, call notifyRecordUpdateAvailable(recordIds) so Lightning Data Service refetches them and all components wired to those records update. It replaces the deprecated getRecordNotifyChange().

04

A developer writes this code to update an Opportunity from an LWC: const fields = {}; fields[STAGE_FIELD.fieldApiName] = 'Closed Won'; updateRecord({ fields }); The promise rejects. What is missing?

  1. The record Id must be included in fields, for example fields[ID_FIELD.fieldApiName] = this.recordId
  2. The apiName property must be set to 'Opportunity' in the recordInput
  3. updateRecord() must be called inside a @wire decorator
  4. The method must be wrapped in refreshApex() to commit the change
Show answer

Answer: A

A. The record Id must be included in fields, for example fields[ID_FIELD.fieldApiName] = this.recordId ✓Correct. updateRecord() identifies the record to update through the Id value inside the fields object.
B. The apiName property must be set to 'Opportunity' in the recordInputapiName is required for createRecord(), not for updateRecord().
C. updateRecord() must be called inside a @wire decoratorupdateRecord() is an imperative function that returns a promise; it is not used with @wire.
D. The method must be wrapped in refreshApex() to commit the changerefreshApex() refreshes wired Apex data and has no role in committing an LDS update.

Why: With updateRecord(recordInput), the fields object must contain the record Id along with the fields to change. createRecord() instead requires apiName and must not include an Id.

05

A utility company has two unrelated LWCs on the same Lightning app page: a map and a list of service outages. Selecting an outage in the list must center the map on it. The components are not in the same DOM hierarchy. What must the developer create first?

  1. A Platform Event and an Apex trigger that publishes it
  2. An Aura application event registered in both components
  3. A LightningMessageChannel metadata file (.messageChannel-meta.xml) that both components import
  4. A CustomEvent with bubbles: true and composed: true dispatched from the list
Show answer

Answer: C

A. A Platform Event and an Apex trigger that publishes itPlatform Events are for server-side, cross-system messaging and add unnecessary round trips for UI coordination on one page.
B. An Aura application event registered in both componentsAura application events are not used by Lightning Web Components, and LMS is the recommended replacement.
C. A LightningMessageChannel metadata file (.messageChannel-meta.xml) that both components import ✓Correct. Lightning Message Service needs a message channel defined in metadata, which components import with @salesforce/messageChannel.
D. A CustomEvent with bubbles: true and composed: true dispatched from the listDOM events only travel up the containment hierarchy, so they cannot reach an unrelated sibling component.

Why: Lightning Message Service lets components that are not in the same DOM tree communicate. A LightningMessageChannel is deployed as metadata, then components publish and subscribe using MessageContext.

06

A grandchild LWC (c-line-item) is rendered inside c-order-lines, which is inside c-order-page. c-order-page must handle an event dispatched by c-line-item without c-order-lines re-dispatching it. Which CustomEvent configuration achieves this?

  1. new CustomEvent('itemchange', { bubbles: true })
  2. new CustomEvent('itemchange', { bubbles: true, composed: true })
  3. new CustomEvent('itemchange', { composed: true })
  4. new CustomEvent('itemchange', { cancelable: true })
Show answer

Answer: B

A. new CustomEvent('itemchange', { bubbles: true })bubbles alone lets the event travel inside c-order-lines' shadow tree but stops at its shadow boundary.
B. new CustomEvent('itemchange', { bubbles: true, composed: true }) ✓Correct. bubbles plus composed lets the event bubble up and cross shadow boundaries until it reaches c-order-page.
C. new CustomEvent('itemchange', { composed: true })composed without bubbles lets the event cross the boundary once but it does not continue bubbling up the tree.
D. new CustomEvent('itemchange', { cancelable: true })cancelable only allows preventDefault() to be called; it does not affect propagation.

Why: bubbles: true makes an event propagate up the DOM, and composed: true lets it cross shadow boundaries. Use both sparingly, because such events become part of every ancestor's API.

07

An @AuraEnabled method validates a loan application and must show the user the specific message "Credit score is below the minimum for this product" in the LWC when validation fails. What should the Apex method do?

  1. Return null so the component displays a default error
  2. Throw new AuraHandledException('Credit score is below the minimum for this product')
  3. Call System.debug() with the message so it appears in the browser console
  4. Add the message with ApexPages.addMessage()
Show answer

Answer: B

A. Return null so the component displays a default errorReturning null gives the component no message and does not signal an error through the promise.
B. Throw new AuraHandledException('Credit score is below the minimum for this product') ✓Correct. AuraHandledException sends the custom message to the client, where it is available in the error's body.message.
C. Call System.debug() with the message so it appears in the browser consoleDebug logs are written on the server and are not sent to the client.
D. Add the message with ApexPages.addMessage()ApexPages messages are for Visualforce pages and are not returned to Lightning components.

Why: Throw AuraHandledException from @AuraEnabled methods to return a controlled, user-friendly error message to Lightning components. The component reads it from error.body.message in the catch block or wire error.

08

An LWC calls an external tracking service that can take up to 60 seconds to respond. The org frequently hits the concurrent long-running request limit when many users use the component. Which Apex pattern should the developer use?

  1. A @future(callout=true) method returning the response to the LWC
  2. A Queueable job that the LWC polls every second
  3. A synchronous HttpRequest with setTimeout(120000)
  4. An @AuraEnabled(continuation=true) method that returns a Continuation object with a callback method
Show answer

Answer: D

A. A @future(callout=true) method returning the response to the LWCFuture methods cannot return values to the caller, so the component would never receive the result.
B. A Queueable job that the LWC polls every secondPolling adds many server requests and complexity; it is not the intended pattern for long UI callouts.
C. A synchronous HttpRequest with setTimeout(120000)The maximum callout timeout is 120 seconds, and long synchronous requests are exactly what count against the limit.
D. An @AuraEnabled(continuation=true) method that returns a Continuation object with a callback method ✓Correct. Continuations make the callout asynchronous, so the request does not hold a server thread while waiting for the response.

Why: The Continuation class lets Lightning components and Visualforce make long-running callouts asynchronously. The method returns a Continuation, and a callback method processes the response, so these requests do not count against the concurrent long-running request limit.

09

A developer adds a controller extension to a Visualforce page that uses standardController="Claim__c". The page fails to save with an error about the extension's constructor. Which constructor signature is required?

  1. public ClaimExt() { }
  2. public ClaimExt(Claim__c record) { }
  3. public static ClaimExt getInstance(ApexPages.StandardController ctrl) { }
  4. public ClaimExt(ApexPages.StandardController stdController) { }
Show answer

Answer: D

A. public ClaimExt() { }A no-argument constructor is used by custom controllers, not by extensions of a standard controller.
B. public ClaimExt(Claim__c record) { }The framework passes the controller instance, not the record, to the extension's constructor.
C. public static ClaimExt getInstance(ApexPages.StandardController ctrl) { }Visualforce instantiates extensions through a constructor, not a static factory method.
D. public ClaimExt(ApexPages.StandardController stdController) { } ✓Correct. An extension of a standard controller must have a constructor that takes a single ApexPages.StandardController argument.

Why: A controller extension's constructor receives the controller it extends: ApexPages.StandardController for a standard controller, or the custom controller type. The extension typically calls getRecord() on it to access the current record.

10

A compliance team needs a Visualforce page that displays an audit list of up to 8,000 Log_Entry__c rows in an apex:dataTable and never modifies data. The page currently hits the collection size limit. What should the developer set?

  1. cache="true" on the apex:page component
  2. transient on the controller list variable
  3. readOnly="true" on the apex:page component
  4. rendered="false" on rows beyond 1,000
Show answer

Answer: C

A. cache="true" on the apex:page componentPage caching affects how long the browser caches the page, not governor limits on queries or collections.
B. transient on the controller list variableTransient reduces view state but does not raise the number of items an iteration component can render.
C. readOnly="true" on the apex:page component ✓Correct. Read-only mode raises the SOQL row limit to 1 million and the iteration collection limit from 1,000 to 10,000 items, but disallows DML.
D. rendered="false" on rows beyond 1,000Hiding rows does not change how many items the component iterates over.

Why: Setting readOnly="true" on apex:page relaxes limits for pages that only display data: up to 1 million rows queried and up to 10,000 items in iteration components. DML operations are not allowed in this mode.

11

A Visualforce page uses <apex:page controller="ApproveCtrl" action="{!approve}">, where approve() updates the Expense__c record whose Id is in the URL. A security review flags this design. Why?

  1. DML in the page's action attribute runs on page load without a user-submitted form, exposing the page to cross-site request forgery
  2. The action attribute runs before the constructor, so the record Id is not yet available
  3. action methods cannot perform DML in Visualforce
  4. The page will exceed the view state limit because of the action attribute
Show answer

Answer: A

A. DML in the page's action attribute runs on page load without a user-submitted form, exposing the page to cross-site request forgery ✓Correct. A malicious link can make a logged-in user load the page and trigger the update; DML should run from a user action in an apex:form, which includes CSRF protection.
B. The action attribute runs before the constructor, so the record Id is not yet availableThe constructor runs first; the action method executes after it during the initial request.
C. action methods cannot perform DML in VisualforceAction methods can perform DML; the concern is when and how it is triggered.
D. The page will exceed the view state limit because of the action attributeThe action attribute does not add significant view state.

Why: Avoid performing DML in the apex:page action attribute or in constructors and getters. Perform state changes through user-initiated postbacks from apex:form, which include anti-CSRF tokens.

12

A Visualforce edit page has a Cancel button that should return to the previous page even when required fields are blank. Currently, clicking Cancel shows validation errors. What should the developer set on the apex:commandButton?

  1. immediate="true"
  2. rerender="none"
  3. reRender plus an apex:actionRegion around the button only
  4. status="cancelStatus"
Show answer

Answer: A

A. immediate="true" ✓Correct. immediate="true" skips validation and model updates, so the action runs even if inputs are invalid or empty.
B. rerender="none"rerender controls which parts of the page refresh; validation still runs on the submitted fields.
C. reRender plus an apex:actionRegion around the button onlyThis could avoid processing inputs, but immediate="true" is the standard, simpler option for a Cancel button.
D. status="cancelStatus"The status attribute only links to an apex:actionStatus indicator.

Why: Setting immediate="true" on a command component bypasses validation rules and does not apply submitted values to the controller. It is typically used for Cancel or Back actions.

13

A travel app navigates to a custom Lightning tab and passes a trip code in the page state so the target LWC can read it with CurrentPageReference. The value never arrives when the developer uses state: { tripCode: 'NYC24' }. What is wrong?

  1. The target component must import getRecord to read state values
  2. State values can be passed only to standard__recordPage references
  3. Custom state parameters must be namespaced, for example c__tripCode
  4. CurrentPageReference only works inside Visualforce pages
Show answer

Answer: C

A. The target component must import getRecord to read state valuesgetRecord reads record data; page state is read from CurrentPageReference.
B. State values can be passed only to standard__recordPage referencesCustom tabs and other page reference types also support state parameters.
C. Custom state parameters must be namespaced, for example c__tripCode ✓Correct. Custom state keys require a namespace prefix such as c__ (or the package namespace); unprefixed custom keys are not preserved.
D. CurrentPageReference only works inside Visualforce pagesCurrentPageReference is a wire adapter from lightning/navigation used in LWC.

Why: When navigating with a PageReference, custom properties in state must use a namespace prefix, like c__tripCode. The target component reads them through @wire(CurrentPageReference) in pageRef.state.

14

An admin must be able to drag a new LWC onto Account record pages in Lightning App Builder and set a "Max Rows" number for each page. Which two steps are required in the component? (Choose 2)

  1. Set isExposed to true in the .js-meta.xml file and list lightning__RecordPage as a target
  2. Create a .design file that defines the Max Rows attribute
  3. Implement the flexipage:availableForRecordHome interface
  4. Add a property element inside targetConfig for lightning__RecordPage that matches an @api property
  5. Decorate maxRows with @track so the builder can write to it
Show answer

Answer: A, D

A. Set isExposed to true in the .js-meta.xml file and list lightning__RecordPage as a target ✓Correct. A component appears in Lightning App Builder only when it is exposed and declares a supported target.
B. Create a .design file that defines the Max Rows attributeDesign files are used by Aura components; LWC defines builder properties in .js-meta.xml.
C. Implement the flexipage:availableForRecordHome interfaceInterfaces like flexipage:availableForRecordHome apply to Aura components, not LWC.
D. Add a property element inside targetConfig for lightning__RecordPage that matches an @api property ✓Correct. A property in targetConfig exposes a public property such as maxRows for admins to configure in the builder.
E. Decorate maxRows with @track so the builder can write to itBuilder values are passed to public @api properties; @track does not expose a property.

Why: In LWC, Lightning App Builder availability and configurable properties are defined in the component's .js-meta.xml: isExposed, targets, and targetConfigs with property elements that map to @api properties.

15

A field sales LWC uses lightning-datatable with editable columns so reps can update the Quantity__c of several Order_Line__c records at once. Which two steps should the onsave handler perform? (Choose 2)

  1. Read the changed rows from event.detail.draftValues and save them, for example with updateRecord() for each row
  2. Call this.template.querySelector('lightning-datatable').submit()
  3. After a successful save, clear draftValues and refresh the data, for example with refreshApex() or notifyRecordUpdateAvailable()
  4. Set cacheable=false on the wired Apex method so the table saves automatically
  5. Remove the key-field attribute so edits are matched by row index
Show answer

Answer: A, C

A. Read the changed rows from event.detail.draftValues and save them, for example with updateRecord() for each row ✓Correct. The save event exposes edited cells in draftValues, each including the key-field value used to identify the record.
B. Call this.template.querySelector('lightning-datatable').submit()lightning-datatable does not save records itself and has no submit() method.
C. After a successful save, clear draftValues and refresh the data, for example with refreshApex() or notifyRecordUpdateAvailable() ✓Correct. Clearing draftValues removes the edit highlighting, and refreshing ensures the table shows the saved values.
D. Set cacheable=false on the wired Apex method so the table saves automaticallyWired methods must be cacheable, and changing caching does not make the datatable persist edits.
E. Remove the key-field attribute so edits are matched by row indexkey-field is required so each draft value can be tied to the correct record.

Why: lightning-datatable inline editing provides draftValues on the save event but leaves persistence to the developer. Save through LDS or Apex, then reset draftValues and refresh the source data.

Find out if you're ready to pass

Take the free Platform Developer II diagnostic: 20 questions, no account needed. Then unlock all 300 questions, full practice exams and the study guide.

Start the free diagnosticSee plans

Other sections of this exam