1
 showToast() {
     const event = new ShowToastEvent({
         title: 'Get Help',
         message:
             'Salesforce documentation is available in the app. Click ? in the upper-right corner.',
     });
     this.dispatchEvent(event);
 }

 saveModal(){
     try {
         this.openModal = false;
         markImportant({Id: this.row.Id}).then(showToast());
     } catch (exception) {
         console.log(exception);
     }
 }

On saveModal() method I'm getting an exception:

ReferenceError: showToast is not defined.

Could you point out my error, please?

1 Answer 1

6
  1. showToast() is not defined within saveModal function scope, but defined within component scope. To access showToast() member function use this.
  2. You can handle Promise errors using Promise.catch(e) method:
saveModal(){
    this.openModal = false;
    markImportant({Id: this.row.Id})
       .then(() => this.showToast())
       .catch(e => console.log(e));
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .