Here is the logic which is working fine while using the button, but I'm trying to display the notification once the page is loaded.
this logic which I tried,
js:
import { LightningElement,wire,track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import toastMsg from '@salesforce/apex/ToastCtrl.toastMessage';
export default class toastcmp extends LightningElement {
@wire(toastMsg)
toast;
notification(){
const evt = new ShowToastEvent({
title: 'Message',
message:this.toast.data.Message__c,
variant: 'info'
});
this.dispatchEvent(evt);
}
}
html:
<template>
<lightning-button label="Click" onclick={notification}></lightning-button>
</template>
Can anyone provide the solution? I tried using this but it is showing an empty page, it is not working. connectedCallback(){ this.notification(); } Thanks, in advance.
connectedCallback(){ this.notification(); }
works fine on alightning__RecordPage
.this.notification()
inside theconnectedCallback()
for the toast to fire on component load.connectedCallback()
is a standard function for LWCs that'll run on load. developer.salesforce.com/docs/component-library/documentation/…