1

lightning Toast message is not showing when i click on save button. Is that anything wrong in the below code. Please help me on this.

<div class="slds-size_2-of-2">
<lightning-button type="submit" variant="brand" value="AddParent" name="AddParent"   label="Save" onclick={handleonClickParent}>
</lightning-button>
</div>

JS:

handleonClickParent() {

createParentGuardian({
  firstName: this.firstname,
  lastName: this.lastName,
  phone: this.phone,
  email: this.email,
  studentRelation: this.relationship
})
  .then(result => {        
    const evt = new ShowToastEvent({
        title: "success",
        message: "Sucessfully Created",
        variant: "Success"
      })
      this.dispatchEvent(evt);
  })

}

@AuraEnabled
public static void createParentGuardian(string firstName, string lastName, string phone, string email, string studentRelation) {

    system.debug('firstName ' + firstName); 
    system.debug('lastName ' + lastName); 
    system.debug('phone ' + phone); 
    system.debug('email ' + email); 
    system.debug('studentRelation ' + studentRelation); 

    try {            
        Contact newContact = new Contact (
            FirstName = firstName,
            //LastName = lastName,                
            Email = email,
            Phone = phone,
            Student_Relation__c = studentRelation,
            RecordTypeId = '0122w000000HM1pAAG'
        );
        //insert newContact;

    } catch (Exception e) {

    }



}
1
  • Although @sfdcfox is correct, there are some noteworthy issues in the code: 1) handleonClickParent shouldn't have parameters, 2) variant should be a lowercase success 3) The alert(evt) might also have prevented the message even if you weren't in a Visualforce environment. Mar 2, 2020 at 8:03

1 Answer 1

3

The ShowToastEvent is handled by the Lightning Experience. When you're not in the Lightning Experience, this event will not be handled, and have no effect. This includes usage in Visualforce, Classic, Communities, etc. You'll want to build your own custom toast component if you need to show toasts outside of the Lightning Experience. When using any component, always make sure you consult the documentation to verify if a given feature is supported. For anything in a Visualforce page, the component or event must support "Lightning Out."

2
  • Would this include Tableau CRM dashboard components by any chance?
    – xouns
    Feb 18, 2022 at 13:44
  • 1
    @xouns Tableau components seem to be supported in Visualforce, from what I can tell. If you have a specific problem, I'd recommend creating a new question so we can get all the info we need to help you.
    – sfdcfox
    Feb 18, 2022 at 13:55

You must log in to answer this question.

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