function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Princes91221Princes91221 

Unable to print Error toast message

Hope you're doing well.
I want to print an error toast, the pop-up appearing but the message is not printing.
I researched and tried a lot about that but was unsuccessful.
Below is my JS controller.
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
handleTimesheet() {
    saveData({
        firstName :this.firstName,
        lastName :this.lastName,
        accountId :this.recordId
    })
    .then(result => {
        //Shows Success Toast Event
        const e = new ShowToastEvent({
            title: 'Success',
            message: result,
            variant: 'success',
            mode: 'dismissable',
        });
        this.dispatchEvent(e);
        // console.log('result: ' +result);
    })
    .catch(error => {
        //Shows Error Toast Event
        const e = new ShowToastEvent({
            title: 'Error Occured',
            message: error.body.message,
            // I TRIED THIS AND THE BELOW LINE AS WELL
            message: error.body.output.errors[0].message,
            // I GOT ERROR ON THIS LINE "Cannot read properties of undefined (reading 'errors')"
            variant: 'error',
            mode: 'dismissable',
        });
        this.dispatchEvent(e);
        console.log('Error: ', JSON.stringify(error));
    })
}

Any help would be appreciated.

Thanks and Regards,
Prince Sharma.
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

Please refer the below article will help you to proceed further.

https://developer.salesforce.com/docs/component-library/documentation/en/lwc/use_toast
https://www.sfdcpoint.com/salesforce/lightning-web-component-lwc-toast-messages/

Thanks!!
Princes91221Princes91221
Hello,

I've checked both the link yestarday.

Thanks!