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
Veni KorapatyVeni Korapaty 

lightning web component Toast SLDS Change

How to display multiple line toast messages? 
AbhishekAbhishek (Salesforce Developers) 
Hi Venki,

The below blog might answer your query,

https://salesforce.stackexchange.com/questions/195129/show-lightning-toast-message-in-multiple-lines

https://salesforce.stackexchange.com/questions/278366/how-to-show-toast-message-in-multiple-lines-in-a-lightning-web-component

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.
 
Caleb Kuester 27Caleb Kuester 27
I think you should be able to add new-line characters to the text.
Prady01Prady01
Hi there, You can use message template in the toat.

Hope this helps!
Prady01
karan sharma 61karan sharma 61
For Multiple Lines Toast in LWC 

we have to override CSS :

1) Create a CSS file and add in static resource

File Content :

.toastMessage{
    white-space: break-spaces !important;
}

2) Import That static resource file in your component

import { loadStyle } from 'lightning/platformResourceLoader';
import CUSTOMCSS from '@salesforce/resourceUrl/{yourfileName}'

a) Define variable like : isCssLoaded = false;

3) Call it in reRenderCallback

renderedCallback(){
    if(this.isCssLoaded) return
    this.isCssLoaded = true;
    loadStyle(this,CUSTOMCSS).then(()=>{
        console.log('loaded');
    })
    .catch(error=>{
        console.log('error to load');
    });For Multiple Lines Toast in LWC 

we have to override CSS :

1) Create a CSS file and add in static resource

File Content :

.toastMessage{

    white-space: break-spaces !important;
}

2) Import That static resource file in your component

import { loadStyle } from 'lightning/platformResourceLoader';

import CUSTOMCSS from '@salesforce/resourceUrl/{yourfileName}';

a) Define variable like : isCssLoaded = false;

3) Call it in reRenderCallback

renderedCallback(){

    if(this.isCssLoaded) return
    this.isCssLoaded = true;
    loadStyle(this,CUSTOMCSS).then(()=>{
        console.log('loaded');
    })
    .catch(error=>{
        console.log('error to load');
    });

}

4)Create your toast message like this

var msg = 'This is first-line \nThis is Second Line. \nThis is third Line.';

const evt = new ShowToastEvent({

                title: "Complete Required Fields :",
                message: msg,
                variant: "error",
            });
            this.dispatchEvent(evt);
}

4)Create your toast message like this
var msg = 'This is first line \nThis is Second Line. \nThis is third Line.';
const evt = new ShowToastEvent({
                title: "Complete Required Fields :",
                message: msg,
                variant: "error",
            });
            this.dispatchEvent(evt);
Guilherme Lupi e SilvaGuilherme Lupi e Silva
That work very well for me! Thanks Bro
Gary RalstonGary Ralston
Hello Veni,

To display multiple line Toast Messages in Salesforce, you need to add line breaks to the message string. You can use the escape sequence "\n" to add a line break in the message. Here is an example :
showToast({
    title: "Success",
    message: "Line 1\nLine 2\nLine 3",
    variant: "success"
});
To learn about customizing Toast Messages in Salesforce, visit at https://logcodes.com/toast-message-in-lwc/, This guide provides a comprehensive overview of toast messages in Lightning Web Components, along with step-by-step instructions on creating different toast messages.