Courseiva
User Interface →mediumMultiple Choice

SF-PD2 User Interface Practice Question

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?

⚠ Common 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.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

import { ShowToastEvent } from 'lightning/platformShowToastEvent';

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.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    import { ToastEvent } from 'lightning/notifications';

    Why it's wrong here

    The lightning/notifications module is used for subscribing to and unsubscribing from notifications, not for displaying toast messages. It does not export ToastEvent. A developer might confuse notifications with toasts because both alert users, but only the platformShowToastEvent module provides the event needed to display a toast in this component.

  • ✗

    import Toast from 'lightning/toast';

    Why it's wrong here

    There is no standard Lightning Web Component module named lightning/toast that exports a Toast class for showing notifications. A developer might assume a simpler toast API exists, but the supported mechanism is ShowToastEvent from lightning/platformShowToastEvent. Importing a non-existent module would cause a compilation error, so this cannot satisfy the requirement.

  • ✗

    import { showToast } from 'lightning/uiRecordApi';

    Why it's wrong here

    The lightning/uiRecordApi module provides wire adapters and functions such as getRecord, createRecord, and updateRecord for working with record data. It does not export a toast function. Using it here would fail because the named import does not exist, and it would not render any notification to the user regardless of the Apex error code returned.

  • ✓

    import { ShowToastEvent } from 'lightning/platformShowToastEvent';

    Why this is correct

    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.

About these practice questions

One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Salesforce exam blueprint

This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.