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
Rasbehari DasRasbehari Das 

How to show multiple line using toast message in LWC

import { ShowToastEvent } from 'lightning/platformShowToastEvent';

const evt = new ShowToastEvent({
  title: 'Title',                        message: 'Description should be 20 charter. \n Campaign Name Must  be 10 Character',
  variant: 'error',                      
                               
                            });
                            this.dispatchEvent(evt);
 Here I used \n it is not working.
please help me
Thanks
 
AbhishekAbhishek (Salesforce Developers) 
Have a read of this article on SFDC Monkey that covers this exact issue! 

http://sfdcmonkey.com/2018/05/05/multiline-toast-message-lightning-component/

For further reference check the below blog too,

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

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

Thanks.
 
Vaibhav Bhargava 11Vaibhav Bhargava 11
I have a solution to it by making our own custom toast component. It is very basic but it solved the problem for me.
HTML
<template>
    <div class="slds-notify_container slds-is-relative">
        <div class={topClass} role="status">
          <span class="slds-assistive-text">{notificationType}</span>
          <lightning-button-icon icon-name={iconName} size="large" variant="bare" alternative-text={notificationType} title={notificationType}></lightning-button-icon>
          <div class="slds-notify__content" style="padding-left: 10px;">
            <template for:each={messageList} for:item="item" for:index="index" >
                <li class="slds-text-heading_small" key={item.keyIndex}>{item}</li>
            </template>
          </div>
          <div class="slds-notify__close">
            <lightning-button-icon icon-name="utility:close" size="large" variant="bare" alternative-text="Close" title="Close" onclick={closeWarningComp}></lightning-button-icon>
          </div>
        </div>
      </div>
</template>

JS

import { LightningElement,api } from 'lwc';

export default class CustomToast extends LightningElement {
    @api messageList = [];
    @api timeOut = 4000; //default close after 3 secs
    @api type = 'dismissible'; //default dismissible
    @api notificationType = 'info';
    @api topClass = 'slds-notify slds-notify_toast slds-theme_info';
    connectedCallback() {   
        if(this.notificationType == 'warning') {
            this.topClass = 'slds-notify slds-notify_toast slds-theme_warning';
            this.iconName = 'utility:warning';
        }
        else if(this.notificationType == 'success') {
            this.topClass = 'slds-notify slds-notify_toast slds-theme_success';
            this.iconName = 'utility:success';
        }
        else if(this.notificationType == 'error') {
            this.topClass = 'slds-notify slds-notify_toast slds-theme_error';
            this.iconName = 'utility:error';
        }
        else {
            this.topClass = 'slds-notify slds-notify_toast slds-theme_info';
            this.iconName = 'utility:info';
        }
        if(this.type == 'dismissible') {
            setTimeout(() => {
                const selectedEvent = new CustomEvent("closewarningtoast");
                this.dispatchEvent(selectedEvent);
            }, this.timeOut);
        }
    }  
    closeWarningComp() {
        const selectedEvent = new CustomEvent("closewarningtoast");
        this.dispatchEvent(selectedEvent);
    }
}

in caller HTML
<template if:true={showWarning}>
        <c-custom-toast
        message-list={warningMessages}
        onclosewarningtoast={closeWarningToast}
        type="dismissible"
        notification-type="warning"
        time-out="4000"
        ></c-custom-toast>
    </template>
    JS
    showWarning() {
        this.warningMessages = [];
        this.warningMessages.push('abc');
        this.warningMessages.push('xyz');
        this.showWarning = true;
    }
    closeWarningToast() {
        this.showWarning = false;
        this.warningMessages = [];
    }