---
url: https://apexfluently.beyondthecloud.dev/libraries/lwc/toast.md
description: >-
  Builder-pattern utility for LWC toast notifications. Fluent API with automatic
  error handling. Clean and minimalistic code.
---

# Toast Builder

A convenient builder-pattern utility for displaying toast notifications.

## Why Toast Builder?

* **Fluent API** - Keep your LWC code clean and minimalistic with the Toast fluent API.
* **Automatic Error Handling** - Just pass the error directly to the message and it will be handled as a single string.

## Quick Start

❌❌❌

```js
const event = new ShowToastEvent({
    title: 'Success!',
    message: 'Record {0} created! See it {1}!',
    messageData: [
        'Salesforce',
        {
            url: 'http://www.salesforce.com/',
                label: 'here',
            },
        ],
    }
);

this.dispatchEvent(event);
```

✅✅✅

```js
import Toast from 'c/toast';

// Show a success toast
Toast.Builder(this)
    .label('Success')
    .message('Record saved successfully!')
    .showSuccess();

// Show an error toast with a reduced error message from the error service
someApexMethod()
    .then(result => {
        // ...
    })
    .catch(error => {
        Toast.Builder(this).message(error).sticky().showError(); // The label will default to 'Error'
    });

```

## Documentation

* [Github Repository](https://github.com/beyond-the-cloud-dev/lwc-utils)

## Installation

* [Copy and Deploy](https://github.com/beyond-the-cloud-dev/lwc-utils/tree/main/force-app/main/default/lwc/toast)
