Skip to content

Instantly share code, notes, and snippets.

@pozil
Last active January 16, 2021 10:18
Show Gist options
  • Save pozil/4a3fedf30836379dd6fc7c8668046f18 to your computer and use it in GitHub Desktop.
Save pozil/4a3fedf30836379dd6fc7c8668046f18 to your computer and use it in GitHub Desktop.
Lightning - Displaying a system toast with a few lines of code
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
<div class="slds-m-around--xx-large slds-text-align--center">
<lightning:button label="Fire toast event" onclick="{! c.fireToastEvent }"/>
</div>
</aura:component>
({
fireToastEvent : function(component, event, helper) {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "It works!",
"type": "success"
});
toastEvent.fire();
}
})
@pozil
Copy link
Author

pozil commented Jul 3, 2017

Deploy the component either:

  • as a new Lightning Component tab
  • in an existing Lightning page using the Lightning Application Builder

@Alimali-Stephen
Copy link

I want to display a toast at an existing component. A notification should show on click of a certain button, how do I go about that?

@pozil
Copy link
Author

pozil commented Jan 15, 2021

Hi @Alimali-Stephen, I'm not sure about what you mean by an existing component. Is that a custom component that you can edit?
If not, you won't be able to plug this code sample into it.

@Alimali-Stephen
Copy link

Yes it's a component that you can edit. I just need to add a method on the code that will show notification to users on click of a button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment