lwc-show-toast-patterns
ShowToastEvent in LWC: variants (success/warning/error/info), modes (dismissible/pester/sticky), message formatting, NOT supported in LWR Experience Cloud sites, alternatives (lightning-alert, inline banners). NOT for custom notification types (use admin/custom-notification-types). NOT for SLDS popovers.
Best use case
lwc-show-toast-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
ShowToastEvent in LWC: variants (success/warning/error/info), modes (dismissible/pester/sticky), message formatting, NOT supported in LWR Experience Cloud sites, alternatives (lightning-alert, inline banners). NOT for custom notification types (use admin/custom-notification-types). NOT for SLDS popovers.
Teams using lwc-show-toast-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/lwc-show-toast-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How lwc-show-toast-patterns Compares
| Feature / Agent | lwc-show-toast-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
ShowToastEvent in LWC: variants (success/warning/error/info), modes (dismissible/pester/sticky), message formatting, NOT supported in LWR Experience Cloud sites, alternatives (lightning-alert, inline banners). NOT for custom notification types (use admin/custom-notification-types). NOT for SLDS popovers.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# LWC ShowToast Patterns
Activate when surfacing user feedback in LWC. `ShowToastEvent` (from `lightning/platformShowToastEvent`) is the idiomatic toast API in Lightning Experience and Experience Cloud Aura sites — but **NOT supported in LWR (Lightning Web Runtime) sites**. Pick the right tool per context.
## Before Starting
- **Determine runtime.** Lightning Experience / mobile Salesforce app / Aura Experience Cloud → ShowToastEvent works. LWR → NOT supported, use alternatives.
- **Pick the variant.** `success` / `warning` / `error` / `info` — each has distinct styling.
- **Pick the mode.** `dismissible` (default, 3s auto), `pester` (stays until dismissed, errors only), `sticky` (stays until dismissed).
## Core Concepts
### Basic dispatch
```
import { LightningElement } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
export default class MyCmp extends LightningElement {
notify() {
this.dispatchEvent(new ShowToastEvent({
title: 'Saved',
message: 'Record updated successfully',
variant: 'success',
mode: 'dismissible'
}));
}
}
```
### Variants
| Variant | When to use |
|---|---|
| `success` | Confirmation of successful action |
| `warning` | Non-blocking caution |
| `error` | Failure requiring attention |
| `info` | Neutral status |
### Modes
| Mode | Behavior |
|---|---|
| `dismissible` (default) | Auto-dismisses after ~3 seconds; user can close |
| `pester` | Stays until user dismisses (only valid for `error` variant) |
| `sticky` | Stays until user dismisses |
### Message placeholders and links
```
this.dispatchEvent(new ShowToastEvent({
title: 'Record Saved',
message: 'See {0}',
messageData: [
{ url: '/lightning/r/Account/0012x.../view', label: 'Acme' }
],
variant: 'success'
}));
```
`{0}` is replaced by the object at index 0 — either plain text or `{url, label}` for a link.
### LWR Experience Cloud caveat
ShowToastEvent is silently ignored on LWR sites. Alternatives:
- `lightning-alert` / `lightning-confirm` modals
- Inline banner component using `lightning-icon` + SLDS notification classes
- Custom toast implementation with `lightning-layout` + CSS animation
## Common Patterns
### Pattern: Error toast with sticky mode
```
this.dispatchEvent(new ShowToastEvent({
title: 'Save failed',
message: error.body.message,
variant: 'error',
mode: 'sticky'
}));
```
### Pattern: Link-in-message toast
```
this.dispatchEvent(new ShowToastEvent({
title: 'Record Created',
message: 'View {0}',
messageData: [
{ url: `/lightning/r/Account/${recordId}/view`, label: accountName }
],
variant: 'success'
}));
```
### Pattern: LWR-compatible fallback
```
// lwrToast.js — a custom banner component
@api message;
@api variant;
isShown = false;
show() { this.isShown = true; setTimeout(() => this.isShown = false, 3000); }
```
## Decision Guidance
| Context | Feedback mechanism |
|---|---|
| Lightning Experience | `ShowToastEvent` |
| Mobile Salesforce app | `ShowToastEvent` |
| Aura Experience Cloud site | `ShowToastEvent` |
| LWR Experience Cloud site | Custom banner, `lightning-alert`, or inline component |
| Blocking confirmation needed | `lightning-confirm` (not a toast) |
| Rich content / interactive | `LightningModal` (not a toast) |
## Recommended Workflow
1. Confirm target runtime (Lightning vs LWR) before writing.
2. Dispatch `ShowToastEvent` with explicit `variant` and `mode`.
3. For errors, use `sticky` or `pester` so users can read.
4. For cross-runtime components, check `@salesforce/client/formFactor` and fall back to a banner in LWR.
5. Test toasts in the actual runtime, not just LEX (LWR renders differently).
6. For accessibility, keep toast messages ≤75 characters so screen readers announce cleanly.
7. Document that LWR does not render toasts — downstream teams must be warned.
## Review Checklist
- [ ] Target runtime verified (LWR alternatives used where needed)
- [ ] Variant matches semantic intent
- [ ] Error variants use `sticky` or `pester` (not `dismissible`)
- [ ] Message kept short for accessibility
- [ ] Link-in-message uses `messageData` placeholders
- [ ] Fallback implemented for LWR sites
## Salesforce-Specific Gotchas
1. **LWR Experience Cloud silently swallows `ShowToastEvent`** — no console warning, just no toast. Use `lightning-alert` or a custom banner.
2. **`pester` mode is only valid for `variant='error'`.** With other variants it falls back to `dismissible`.
3. **Toasts dispatched before the component is fully rendered may be lost.** Use `renderedCallback` or defer to after async work completes.
4. **Custom toast styling is not supported.** `slds-notify_toast` classes apply to the built-in component, not reproducible outside the framework.
## Output Artifacts
| Artifact | Description |
|---|---|
| Toast dispatch helper | Utility wrapping `ShowToastEvent` with defaults |
| LWR fallback component | Banner for Experience Cloud LWR |
| Accessibility snippet | Short message + role='alert' pattern |
## Related Skills
- `lwc/lwc-lightning-modal` — when blocking user attention is required
- `lwc/lwc-accessibility-patterns` — semantic feedback patterns
- `admin/custom-notification-types` — for async/server-side notificationsRelated Skills
mfa-enforcement-patterns
Design MFA enforcement: auto-enablement, Salesforce Authenticator rollout, exceptions, service accounts, API-only users, SSO interop, and audit. Trigger keywords: MFA, multi-factor, two-factor, Salesforce Authenticator, MFA exception, MFA SSO, api-only MFA. Does NOT cover: end-user password policies, device-trust posture, or non-Salesforce IdP configuration.
encrypted-field-query-patterns
Design SOQL, filters, reporting, and indexes against Shield Platform Encryption fields. Trigger keywords: Shield Platform Encryption, encrypted field query, probabilistic vs deterministic encryption, encrypted SOQL filter, encrypted field index. Does NOT cover: Classic Encryption (deprecated), field-level security policy, or tenant secret key rotation.
apex-managed-sharing-patterns
Grant row-level access programmatically via __Share records when declarative sharing rules cannot express the policy. NOT for OWD, role hierarchy, or criteria-based sharing rule design.
omnistudio-testing-patterns
Use when testing or validating OmniStudio components — OmniScript preview, Integration Procedure step debugging, DataRaptor field-mapping validation, and end-to-end UTAM-based automation. NOT for Apex unit testing or standard Flow debugging.
omnistudio-error-handling-patterns
Use when designing fault behavior across Integration Procedures, DataRaptors, OmniScripts, and FlexCards — error routing, user-facing messaging, retry semantics, and idempotency. Triggers: 'omnistudio error', 'integration procedure fault', 'dataraptor error handling', 'omniscript retry', 'flexcard action failure'. NOT for general Apex exception design or Flow fault paths.
omnistudio-ci-cd-patterns
Use when designing or implementing CI/CD pipelines for OmniStudio components — DataPack export/import, versioning, environment promotion, and automated deployment. NOT for standard Salesforce metadata CI/CD or Apex-only pipelines.
omniscript-design-patterns
Use when designing or reviewing OmniScripts for guided experiences, step structure, branching, save/resume, and the boundary between OmniScript, Integration Procedures, DataRaptors, and custom LWCs. Triggers: 'omniscript design', 'too many steps in omniscript', 'save and resume omniscript', 'branching in omniscript', 'when should this be an integration procedure'. NOT for deep Integration Procedure or DataRaptor design when the guided interaction layer is not the main concern.
integration-procedure-cacheable-patterns
Use when designing Integration Procedures (IPs) with platform cache to cut latency and callout load. Covers cache key design, TTL selection, per-user vs org-wide partitions, invalidation on data changes, and safe fallback on cache miss/stale. Does NOT cover general IP authoring (see omnistudio-error-handling-patterns) or LWC client-side caching.
flexcard-design-patterns
Use when designing, building, or reviewing OmniStudio FlexCards — including data source selection, card states, actions, conditional visibility, flyout configuration, and child card iteration. Triggers: 'FlexCard', 'card template', 'flyout', 'card action', 'card state', 'data source', 'child card', 'conditional visibility'. NOT for OmniScript design, standalone LWC development, or Apex controller architecture outside the FlexCard context.
dataraptor-patterns
Use when designing or reviewing OmniStudio DataRaptors, especially Extract versus Turbo Extract versus Transform versus Load, field mapping strategy, performance tradeoffs, and when to move work into Integration Procedures or Apex. Triggers: 'DataRaptor Extract', 'Turbo Extract', 'DataRaptor Load', 'DataRaptor Transform', 'OmniStudio data mapping'. NOT for overall OmniScript journey design or Integration Procedure sequencing when the main question is not the DataRaptor shape itself.
wire-service-patterns
Use when designing or reviewing Lightning Web Components that use `@wire`, Lightning Data Service, UI API, or the GraphQL wire adapter, especially for reactive parameters, cache behavior, and refresh strategy. Triggers: 'wire service', 'refreshApex', 'reactive parameter', 'getRecord', 'wire vs imperative Apex'. NOT for component communication or generic lifecycle issues when data provisioning is not the main concern.
message-channel-patterns
Use when implementing Lightning Message Service (LMS) to enable cross-DOM communication between LWC, Aura, and Visualforce components on the same Lightning page, using message channels. Triggers: 'communicate between unrelated LWC components', 'send data between Visualforce and LWC', 'lightning message service not working', 'APPLICATION_SCOPE vs default scope', 'message channel metadata deployment'. NOT for parent-child component communication (use component-communication) or server-side events.