โก Create a Reusable Toast Utility in Salesforce LWC
Published on December 10, 2025 โข by Anand Kumar Jha
๐น Introduction
Toast messages are one of the most commonly used UI elements in Lightning Web Components (LWC).
But repeating toast logic in every component leads to duplicate code. So today, weโll build a Reusable Toast Utility.
๐ฏ Goal
- Create a universal toast helper function
- Reduce duplicate code across LWCs
- Trigger Success, Error, Warning, and Info toasts
๐ Folder Structure
lwc
โโโ toastUtils
โโโ toastDemo
๐งฉ Step 1: Create toastUtils Utility Module
import { ShowToastEvent } from "lightning/platformShowToastEvent";
const showToast = (cmp, title, message, variant) => {
cmp.dispatchEvent(
new ShowToastEvent({ title, message, variant })
);
};
export { showToast };
๐บ Watch the Full Video
โถ Watch on YouTube๐งพ Conclusion
This reusable toast utility keeps your LWC code clean, modular, and scalable.