9

How to show the message in hyperlink

showToast : function(component, event, helper) {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
    "title": "Success!",
    "message": "The record #123456 has been updated successfully."
});
toastEvent.fire();}

the '#123456' should be in hyperlink.

  • 1
    I don't think you can show links in the toast? The documentation doesn't say you can. – sfdcfox Nov 14 '16 at 6:59
  • 1
    @sfdcfox but the release doc says its available in summer 16 releasenotes.docs.salesforce.com/en-us/summer16/release-notes/… – Saravanan Baskar Nov 14 '16 at 7:00
  • 1
    That's curious. There's no mention in the documentation, as the release notes state there should be. Perhaps someone knows something. Definitely a good question. – sfdcfox Nov 14 '16 at 7:04
6

You can provide an 'action' in the messageTemplateData provided to the showToast event. Here's an example where the link's action becomes creating an event which will trigger a second toast.

showToast: function(component, event, helper) {
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams({
        title: "Success!",
        mode: "sticky",
        message: "has to be defined due to toast event validation, but isn't used.",
        messageTemplate: "The record '{0}' has been updated successfully.",
        messageTemplateData: [{
            label:"#123456",
            url: "#123456",
            executionComponent: {
                descriptor: "markup://force:showToast",
                attributes: {mode: 'sticky', message:"second toast"},
                isEvent: true,
                isClientSideCreatable: true,
                componentName: 'showToast'
            }
        }]
    });
    toastEvent.fire();
}
  • This is excellent... but how do I make that link navigate to the desired url? – Sebastian Kessel Jan 16 '17 at 20:28
  • 1
    You could have your own custom event you put in the action (instead of the second showToast). Then have your component handle that event and in the handler set window.location (if you really want to navigate to a new page), but with the lightning experience you should ideally just load the new component or lightning page that you are trying to get the user to go to – Luke Inman-Semerau Jan 19 '17 at 22:10
  • is there documentation around the "executionComponent" syntax anywhere? I cannot seem to figure out how to trigger a custom event - ex: { descriptor: "markup://myNamespace:myEvent", attributes: { att_1: 'foo', att_2: 'bar' }, componentName: 'myEvent', isEvent: true, isClientSideCreateable: true } – Andrew Turgeon Aug 16 '18 at 19:37
4
var resultsToast = $A.get("e.force:showToast");
                resultsToast.setParams({
                    mode: 'sticky',
                    message: 'This is a required message',
                    messageTemplate: 'Record {0} created! See it {1}!',
                    messageTemplateData: ['Salesforce', {
                    **url: 'https://xx-dev-ed.lightning.force.com/one/one.app?source=alohaHeader#/sObject/'**+recId,
                    label: 'here',
                }]

            });
            resultsToast.fire();

The url currently is hardcoded, but can be removed programetically

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.