Thursday, May 23, 2019

force:showToast Message Display In Multiple Lines In Salesforce Lightning Component

force:showToast Message Display In Multiple Lines In Salesforce Lightning Component


Dear Devs,

Today in this post I am going to share a workaround for salesforce lightning force:showToast event to display toast message in multiple lines. without any custom code. 


I will be using the power of aura:html tag to do that append this to your lightning component 

<aura:html tag="style">.toastMessage.forceActionsText{
white-space : pre-line !important;
}</aura:html>
Add this to your helper js file.
showToast: function (message) {
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Action not allowed!",
"message": message,
"type" : "error",
"mode" : "sticky"
});
toastEvent.fire();
},

Not the controller or any other helper method invoke the show mesage method
myfun : function(component,event,helper){
var errMessage = "This is my first error message. \n" ;
errMessage += "This is my senond error message. \n" ;
errMessage += "This is my third error message. \n" ;
helper.showToast(errMessage);
}
The message will appar like above and no custom component is needed to achive that.
Hope this will save your time



1 comment:

  1. Thanks for this psot!

    How to change the background color as custom color for Toast message

    ReplyDelete

Tips on passing Salesforce AI Associate Certification

  🌟 Motivation to Pursue the Salesforce AI Associate Certification 🌟 The world of technology is in a state of perpetual evolution, and on...