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
LinThawLinThaw 

Show message with multiple lines using showToast

Hi there,
I want to use showToast and
show message with multiple lines.
I tried as follow but \n is not working well.
({
    fireToastEvent : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");    
        toastEvent.setParams({
            "title": "Title",
            "message": "This is line 1. \n This is line 2. \n This is line 3.",
            "type": "success"
        });
        toastEvent.fire();
    }
})
is there any idea?

Regards,
LinThaw
 
Best Answer chosen by LinThaw

All Answers

GauravGargGauravGarg

Hi Lin,

Please try <br> insted of \n. This might help else need to Javascript coding. 

Thanks,

Gaurav
Skype: gaurav62990

LinThawLinThaw
Thanks GauravGarg,
I tried <br> also.
But not going to new line.
Regards,
LinThaw
LinThawLinThaw
Thanks GauravGarg,
I also try that way.
I think line break is not working for message of showToast.
Regards,
LinThaw
sfdcMonkey.comsfdcMonkey.com
This was selected as the best answer
LinThawLinThaw
Thanks you Piyush,
Nice override way.
Regards,
LinThaw
Madhankumar VisvakumarMadhankumar Visvakumar
Hi LinThaw,
This can also be achieved by this method which will be very simple. Just add the below mentioned code in your component.
Component:
<aura:html tag="style">.toastMessage.forceActionsText{
white-space : pre-line !important;
}</aura:html>

And In the message put  "\n" in the place you want new line.
Example.js:
({
    fireToastEvent : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");    
        toastEvent.setParams({
            "title": "Title",
            "message": "This is line 1. \n This is line 2. \n This is line 3.",
            "type": "success"
        });
        toastEvent.fire();
    }
})

Hope this helps for new Lightning developers.

Thanks,
Madhan

 
satya Vishwakarmasatya Vishwakarma
Thanks Piyush. It works.