[SalesForce] lightning Toast message in LWC in Visual force page is not working

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) {

    }



}

Best Answer

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."