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
Tejas Wadke 5Tejas Wadke 5 

How to add new line to apex email body

Hello,

This is my apex email body in the code.

   String body = 'Dear ' + con.firstname + ' ' + con.lastname + ',   ';
body += 'Thank you for considering us for your on-going software development needs. We sincerely value the opinion of our customers, and we would love to hear your opinion on our services which would help us improve the same.Please take a few minutes to complete the Feedback form by visiting the link given below.' ;
body +=  'Here’s the link  https://appfeedback-developer-edition.na30.force.com/survey/?email='+con.email+'&fullname='+con.firstname+ +con.lastname
 body += 'Best Regards,' ;

I want each of these lines on the new line.Currently it is displaying  in email as.

Dear Tejas Wadke, Thank you for considering us for your on-going software development needs. We sincerely value the opinion of our customers, and we would love to hear your opinion on our services which would help us improve the same.Please take a few minutes to complete the Feedback form by visiting the link given below. Here’s the link https://appfeedback-developer-edition.na30.force.com/survey/?email=tejas.wadke@aress.com&fullname=TejasWadkeBest Regards,https://www.tester.com?fullname=con.firstname+con.lastname

 
Mani RenusMani Renus

Hi,

You can use the setHtmlBody() method.

Example:

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

// use the html body to set the content of the body
mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created.<p>'+
      'To view your case <a href=https://na1.salesforce.com/'+case.Id+'>click here.</a>');
BALAJI CHBALAJI CH
Hi Tejas,
You can use New line character '\n' to display contentin separate lines.

Please find modified code and Let me know if that helps you.
 
String body = 'Dear ' + con.firstname + ' ' + con.lastname + ',  \n ';
body += 'Thank you for considering us for your on-going software development needs. \n We sincerely value the opinion of our customers, and we would love to hear your opinion on our services which would help us improve the same. \n Please take a few minutes to complete the Feedback form by visiting the link given below. \n' ;
body += 'Here’s the link  https://appfeedback-developer-edition.na30.force.com/survey/?email='+con.email+'&fullname='+con.firstname+''+con.lastname+' ';
body += '\n Best Regards,' ;

Best Regards,
BALAJI
Ravanakol BaluRavanakol Balu
Hi Tejas,
You can use the setHtmlBody() method and break tag  '<br/>' when you want to display  contentin separate lines.

Please find modified code and Let me know if that helps you.

 String body = 'Your Attention Please!  '+','+'<br/>';
            body += 'Below Batch Job(s) are expiring in a week please take necessary action.'+'<br/>';
            body += '<b>Batch Job name :<b/>'+ct.CronJobDetail.Name+' '+'<b>Batch Job start Date :</b>'+ct.StartTime+' '+'<b>Batch Job End Date :               </b>'+ct.EndTime+'<br/>';
            body +='Regards'+','+'\n Batch Monitoring'+'<br/>';
            body +='<b>Internal Team mail id:</b>'+'  '+'sf.internal@castandcrew.com'+'<br/>';
            mail.setHtmlBody(body);

Best Regards,
Balu.