zhangqian
2023-07-04 32944d1a233be29c0cb27d8ad4f21df868fb98a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { LightningElement } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { reduceErrors } from 'c/ldsUtils';
import callApex from '@salesforce/apex/PageMessagesControllerLwc.callApex';
 
export default class PageMessagesToast extends LightningElement {
    handleButtonClick() {
        callApex()
            .then(() => {
                // Handle successful result
            })
            .catch((error) => {
                const evt = new ShowToastEvent({
                    title: 'Error',
                    message: reduceErrors(error).join(', '),
                    variant: 'error'
                });
                this.dispatchEvent(evt);
            });
    }
}