Please let me know if there is a way to show a message right after opening a Lightning Page for three/few seconds and continue. I need this function to be happened without pressing any button. Once the page is opened, it should show the custom message and disappear after three seconds and continue with normal PAGE. Please suggest me if there is a way to do this in LIGHTNING.. I have a piece of code, please let me know if I can include that in init controller along with previous/original page code??

errMessage: function (cmp, event, helper){
    //helper.error(cmp, event);
    var invId = event.getParam("invId");
    var action = component.get("c.errMessage");
    var myEvent = $A.get("e.c:ShowMessage");
        "invId": invId
    action.setCallback(this, function(a) {
        var err = a.getReturnValue().toString();
        var returnStringArr = err.split(':'); 
        var msgType = returnStringArr[0];
        var msg = returnStringArr[1];
        setTimeout(function() {
                myEvent.setParams({"msg": msg, "msgType":msgType});
                }, 3000);

Thanks in advance. Ashok

  • you can create a lightning component do the stuff you wanted to appear in Init function and place the component in lightning page
    – vignesh
    Sep 3 '18 at 9:57
  • @vignesh Thank you for the quick response. Please let me know if we can include above mentioned code in along with actual/existing controller or not.
    – AshSFcloud
    Sep 3 '18 at 10:13
  • You have already another component in the page right ? You mentioning "actual/existing controller" I cant get you clearly
    – vignesh
    Sep 3 '18 at 10:23
  • Yes. I already have some code in the same init controller of Lightning page. it is already calling a method var action = component.get("c.checkInvoiceStatus"); Now, I want to call another method on same class which is returning ERROR and I want to use above code to display that message.
    – AshSFcloud
    Sep 3 '18 at 10:28
  • Yes you can .What is event.getParam("invId") Is there any event or method which calls the errMessage method .Now you calling in init it will return undefined, may be you can take care of that. And use $A.getCallback() to window.setTimeout() in an event handler to execute some logic after a time delay.developer.salesforce.com/docs/atlas.en-us.lightning.meta/…
    – vignesh
    Sep 3 '18 at 10:41

Try using force:showToast This basically shows a message which disappears after a few second.

Use duration parameter to specify the time interval.


I would instead advise using the Toast from the lightning:notificationsLibrary component.

When your component initializes, you can fire the event that will display the Toast, and specify the modality to sticky which will display it for 3 seconds:

using the init handler ->

    handleShowToast : function(component, event, helper) {
            "title": "Notif library Title!",
            "message": "Your Message",
            "mode" : "sticky"


in your component markup, you will have to use a <lightning:notificationsLibrary aura:id="notifLib"/> component.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.