0

I Used showToast() method to get a success message with a toast when my method work correctly but I get the same toast message even if my method don't return any value (the case when I get an error I have the get the same message ) I don't know where is the problem

@track canc = false ;
  myMethod(){
        getName({TemplateId: this.recordId, value : this._selected.toString()})
     console.log('record id is:'+this.recordId);
            console.log('selected is: '+this._selected);
            if(this.canc){
                console.log('success'+this.canc);
                const event = new ShowToastEvent({
        title: '',
                    message: 'successfully',
                    variant: 'success',
                    mode: 'dismissable'        
               });
               this.canc= true;
               this.dispatchEvent(event);
               this.dispatchEvent(new CloseActionScreenEvent());
        
           }else {
        
               console.log('eeeeeroooooooooorrrpopup'+this.canc);
              const evt = new ShowToastEvent({
                   title: 'Error',
                   message: 'Please check that all rules are respected',
                   variant: 'Error',
                   mode: 'dismissable'
        
                   });
        
                   this.dispatchEvent(evt);
        
               }  
        
    }

1 Answer 1

1

You have to put a check for the result returned from the apex method.

    myMethod(){
        getName({TemplateId: this.recordId, value : this._selected.toString()})
            console.log('record id is:'+this.recordId);
            console.log('selected is: '+this._selected);
            if(this._selected){
                const event = new ShowToastEvent({
                    title: '',
                    message: 'successfully',
                    variant: 'success',
                    mode: 'dismissable'        
               });
               this.dispatchEvent(event);
               this.dispatchEvent(new CloseActionScreenEvent());
        
            }else {
              const evt = new ShowToastEvent({
                   title: 'Error',
                   message: 'Please check that all rules are respected',
                   variant: 'Error',
                   mode: 'dismissable'
               });
        
               this.dispatchEvent(evt);
           }  
        
     }


               

If you want to use this.canc variable then you need to make it true once you get the result.

You must log in to answer this question.

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