function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prasanth Srinivasan 12Prasanth Srinivasan 12 

toast message not getting displayed on triggering from flow

I'm trying to use the toast message in screen flow after collecting input from user . I have a aura component that displays toast message. I have called this aura component on the flow and passed the message and type for firing the toast message. I don't see any error when the flow is running. But it is just that screen is refreshing but I'm not able to see the toast message getting displayed. Have any of you encountered the same issue please advise
Best Answer chosen by Prasanth Srinivasan 12
ANUTEJANUTEJ (Salesforce Developers) 
I was able to implement this using the simple implementation User-added imageAnd the Component code I used is:
Component:
<aura:component implements="lightning:availableForFlowActions">
    <aura:attribute name="type" type="string" default="success" />
    <aura:attribute name="title" type="string" />
    <aura:attribute name="message" type="string" />    
    <aura:attribute name="key" type="string" default="" />
    <aura:attribute name="mode" type="string" default="dismissable" />
    <aura:attribute name="duration" type="string" default="10" />
    <aura:attribute name="urlLink" type="string" />
    <aura:attribute name="urlLabel" type="string" />
</aura:component>
Controller:
({
    invoke : function(component, event, helper) {

        var type = component.get("v.type").toLowerCase(); //force user entered attribute to all lowercase
        var title = component.get("v.title");
        var message = component.get("v.message");
        var duration = component.get("v.duration")+"000"; //convert duration value from seconds to milliseconds
        var mode = component.get("v.mode").toLowerCase(); //force user entered attribute to all lowercase
        var key = component.get("v.key").toLowerCase();   //force user entered attribute to all lowercase

        var isURL = message.toLowerCase().includes('{url}');  //Did the user include '{url}' in their message?

        if(!isURL){
            helper.showToast(type, title, message, duration, mode, key);
        }

        if(isURL){
          var messageUrl = message.replace('{url}', '{1}');
          var urlLink = component.get("v.urlLink")
          var urlLabel = component.get("v.urlLabel");
          //Add 'http://' to the URL if it is not already included
          if(urlLink.toLowerCase().indexOf('http') == -1){
              urlLink = 'http://' + urlLink;  
          }
          helper.showToastUrl(type, title, messageUrl, urlLink, urlLabel, duration, mode, key);
        }
        
    }
})
Helper:
({
    //Standard Show Toast Event
    showToast : function(type, title, message, duration, mode, key) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": title,
            "message": message,
            "type": type,
            "duration": duration,
            "mode": mode,
            "key": key
        });
        toastEvent.fire();
    },

    //Show Toast Event updated to include a message that contains a link
    showToastUrl : function(type, title, messageUrl, urlLink, urlLabel, duration, mode, key) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": title,
            "message": messageUrl,
            "messageTemplate": messageUrl,
            "messageTemplateData": ['Salesforce', {
                url: urlLink,
                label: urlLabel,
            }],
            "type": type,
            "duration": duration,
            "mode": mode,
            "key": key
        });
        toastEvent.fire();
    }
})
Design:
<design:component >
    <design:attribute name="type" label="Type (success, error, warning, info, other)" default="success" />
    <design:attribute name="title" label="Title" />
    <design:attribute name="message" label="Message" />
    <design:attribute name="key" label="Icon (only for Type=other)" />
    <design:attribute name="mode" label="Dismissal Mode (dismissible, pester, sticky)" default="dismissible" />
    <design:attribute name="duration" label="Duration in Seconds (minimum is 5, default is 10)" default="10" />
    <design:attribute name="urlLink" label="URL Link" />
    <design:attribute name="urlLabel" label="URL Label" />
</design:component>

Where the action is calling the lightning component.

Link to the above implementation: https://unofficialsf.com/show-toast-flow-action/#:~:text=Version%202.0%20adds%20the%20ability,pop%20up%20a%20toast%20message.

The output I got is:

User-added imageWhere the asdasd if the randm text in the flow screen.

Let me know if this helps.

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Prasanth,

Can you try checking to see if the lightning component is being called, and also can you mention if this is the behaviour you are observing only after the recent update or was it the behaviour even before as well.

Looking forward to your response.

Thanks.
Prasanth Srinivasan 12Prasanth Srinivasan 12

Hi @ANUTEJ,

I clearly see the lightning component is getting called as I have placed some alert message on the component. But the problem is toast message is not appearing even though the screen refresh is happening. This behaviour is happening from first as I have tried the concept last two days. 

ANUTEJANUTEJ (Salesforce Developers) 
In that case, can you provide the code that you have used and how you are passing the message from the flow to test and check where the issue might be occurring.
ANUTEJANUTEJ (Salesforce Developers) 
I was able to implement this using the simple implementation User-added imageAnd the Component code I used is:
Component:
<aura:component implements="lightning:availableForFlowActions">
    <aura:attribute name="type" type="string" default="success" />
    <aura:attribute name="title" type="string" />
    <aura:attribute name="message" type="string" />    
    <aura:attribute name="key" type="string" default="" />
    <aura:attribute name="mode" type="string" default="dismissable" />
    <aura:attribute name="duration" type="string" default="10" />
    <aura:attribute name="urlLink" type="string" />
    <aura:attribute name="urlLabel" type="string" />
</aura:component>
Controller:
({
    invoke : function(component, event, helper) {

        var type = component.get("v.type").toLowerCase(); //force user entered attribute to all lowercase
        var title = component.get("v.title");
        var message = component.get("v.message");
        var duration = component.get("v.duration")+"000"; //convert duration value from seconds to milliseconds
        var mode = component.get("v.mode").toLowerCase(); //force user entered attribute to all lowercase
        var key = component.get("v.key").toLowerCase();   //force user entered attribute to all lowercase

        var isURL = message.toLowerCase().includes('{url}');  //Did the user include '{url}' in their message?

        if(!isURL){
            helper.showToast(type, title, message, duration, mode, key);
        }

        if(isURL){
          var messageUrl = message.replace('{url}', '{1}');
          var urlLink = component.get("v.urlLink")
          var urlLabel = component.get("v.urlLabel");
          //Add 'http://' to the URL if it is not already included
          if(urlLink.toLowerCase().indexOf('http') == -1){
              urlLink = 'http://' + urlLink;  
          }
          helper.showToastUrl(type, title, messageUrl, urlLink, urlLabel, duration, mode, key);
        }
        
    }
})
Helper:
({
    //Standard Show Toast Event
    showToast : function(type, title, message, duration, mode, key) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": title,
            "message": message,
            "type": type,
            "duration": duration,
            "mode": mode,
            "key": key
        });
        toastEvent.fire();
    },

    //Show Toast Event updated to include a message that contains a link
    showToastUrl : function(type, title, messageUrl, urlLink, urlLabel, duration, mode, key) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": title,
            "message": messageUrl,
            "messageTemplate": messageUrl,
            "messageTemplateData": ['Salesforce', {
                url: urlLink,
                label: urlLabel,
            }],
            "type": type,
            "duration": duration,
            "mode": mode,
            "key": key
        });
        toastEvent.fire();
    }
})
Design:
<design:component >
    <design:attribute name="type" label="Type (success, error, warning, info, other)" default="success" />
    <design:attribute name="title" label="Title" />
    <design:attribute name="message" label="Message" />
    <design:attribute name="key" label="Icon (only for Type=other)" />
    <design:attribute name="mode" label="Dismissal Mode (dismissible, pester, sticky)" default="dismissible" />
    <design:attribute name="duration" label="Duration in Seconds (minimum is 5, default is 10)" default="10" />
    <design:attribute name="urlLink" label="URL Link" />
    <design:attribute name="urlLabel" label="URL Label" />
</design:component>

Where the action is calling the lightning component.

Link to the above implementation: https://unofficialsf.com/show-toast-flow-action/#:~:text=Version%202.0%20adds%20the%20ability,pop%20up%20a%20toast%20message.

The output I got is:

User-added imageWhere the asdasd if the randm text in the flow screen.

Let me know if this helps.
This was selected as the best answer
Prasanth Srinivasan 12Prasanth Srinivasan 12
thank you @Anutej this example is working great.
Moulika SeepanaMoulika Seepana
@Anutej, Can you help me to understand what do we need to select in action in the flow?
Dinesh RajendranDinesh Rajendran
Above code is working fine if I directly use my flows in a record page.
However toast message is not displaying if I call the flow from the related list button as a URL.
pavan kumar 1950pavan kumar 1950
@dinesh rajendran.
I have also have same requirement that im calling a Aura component inside the Screen flow and im launching the screen flow from the custom button as a URL and what i have seen is any events wont be fired and not just the Toast message event.
So have you came across with the solution and can you please share the Workaround for this?