SF-PD2 User Interface Practice Question
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?
⚠ Common 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.
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 and dispatch it with new ShowToastEvent({ title, message, variant }).
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.
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 ShowToastEvent from lightning/platformShowToastEvent and dispatch it with new ShowToastEvent({ title, message, variant }).
Why this is correct
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.
- ✗
Use the lightning-toast base component and set its title, message, and variant attributes in the template.
Why it's wrong here
There is no lightning-toast base component in the Lightning Web Components library. Toasts are not rendered declaratively; they are triggered by dispatching a ShowToastEvent. Using a non-existent component would result in a template compilation error, and even if it existed, it would not integrate with the platform toast service.
- ✗
Import toast from lightning/toast and call toast.show({ title, message, variant }).
Why it's wrong here
There is no lightning/toast module in the Lightning Web Components framework. The correct module is lightning/platformShowToastEvent, and toasts are shown by dispatching an event, not by calling a show method. This import would fail at build time or runtime, so the toast would never appear.
- ✗
Import ShowToastEvent from lightning/platformShowToastEvent and call this.ShowToastEvent({ title, message, variant }) without dispatching.
Why it's wrong here
ShowToastEvent is a class that must be instantiated with new and then dispatched. Calling it as a method on the component does not create or dispatch an event, so no toast appears. The event must be dispatched through the component's dispatchEvent method to bubble up to the Lightning Experience toast container.
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 →
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.