Skip to main content

Inserting Line breaks in Apex email message Salesforce

 To insert line breaks with setPlainTextBody method from SingleEmailMessage, Use '\n' character.


Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setPlainTextBody('Hi \n \n' + 'Welcome to Gavan');

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

To insert line breaks with setHtmlBody method from SingleEmailMessage, use <br> tag


Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setHtmlBody('<html><body>Hi <br/><br/>'+'Welcome to Gavan </body></html>');

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); 


Comments