Courseiva
User Interface →mediumMultiple Choice

SF-PD2 User Interface Practice Question

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?

⚠ Common exam trap

Candidates often confuse the class name with a function name or using a default import when the module only provides named exports.

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';

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.

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 { showToast } from 'lightning/platformShowToastEvent';

    Why it's wrong here

    The lightning/platformShowToastEvent module does not export a function named showToast. The correct named export is ShowToastEvent, which is a class that extends Event. Attempting to import showToast will result in a build error because the export does not exist. Developers often confuse the method name with the class name, but the module only provides the ShowToastEvent class for manual instantiation and dispatch.

  • ✗

    import ShowToastEvent from 'lightning/platformShowToastEvent';

    Why it's wrong here

    This uses a default import, but lightning/platformShowToastEvent does not have a default export. All exports from this module are named exports. Using a default import will cause a syntax or build error because the module does not provide a default export. The correct syntax requires curly braces around the named export ShowToastEvent. Developers must use named imports for all standard Lightning modules.

  • ✓

    import { ShowToastEvent } from 'lightning/platformShowToastEvent';

    Why this is correct

    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.

  • ✗

    import { ShowToastEvent } from 'lightning/toastEvent';

    Why it's wrong here

    The module path 'lightning/toastEvent' does not exist in the Lightning Web Components framework. The correct module is 'lightning/platformShowToastEvent'. Using an incorrect module path will cause a module resolution error during compilation. Developers should always verify the exact module names from the official Salesforce documentation, as the framework provides a specific set of base Lightning components and modules with fixed names.

About these practice questions

Courseiva writes every SF-PD2 question from scratch — 226 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.