How to create a timed fade out message using force:showToast

So this is pretty simple to create. I have the code:

showMessage : function(){
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams({
        mode : "dismissable",
        message : "My Message",
        type : "success",
        duration : 1000
    });
    toastEvent.fire();
}

The problem with this, is that the toast message that shows up disappears after 5 seconds when it should disappear after 1 second. The Salesforce documentation states that the duration has a default value of 5000 milliseconds (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_showToast.htm), but it does not let me enter a value lower than this. I am trying to find a workaround, or if anyone knows a way to get this to work. This would be extremely helpful.

(Seems I am not the only one looking for a solution – https://github.com/salesforce-ux/design-system/issues/296)

Answer

The minimum value for duration is 5000ms. If you gave value less the 5000ms value will be taken as 5000ms.

https://developer.salesforce.com/docs/component-library/bundle/force:showToast/specification

enter image description here

Attribution
Source : Link , Question Author : Nicolas O , Answer Author : Ajith Kumar

Leave a Comment