You need to sign in to do that
Don't have an account?
Raj R.
How to add line breaks in emails sent from salesforce in apex?
Hi,
I have some debug statements and checks that will send an email out when an Apex class fails on a DML operation (insert, update, delete). How can I create a string variable or array (whatever is most appropriate) that when the email is sent and opened in a Email Client (i.e. Outlook) there are line breaks where I want them to be?
Unsuccessful code I have tried:
I have some debug statements and checks that will send an email out when an Apex class fails on a DML operation (insert, update, delete). How can I create a string variable or array (whatever is most appropriate) that when the email is sent and opened in a Email Client (i.e. Outlook) there are line breaks where I want them to be?
Unsuccessful code I have tried:
try { insert list; } Catch(DMLExceptiion dml) { String msg = ''; for(Object ob : list){ msg = msg + ob.Name + '\r\n'; } //at the end of the for loop, the msg variable has a list of all names of the object where there is a new line break after each name //structure of sendEmail method is SendEmail(Subject, Body); Email.SendEmail ('Test', msg); } ------------------------------------------------------------------------ try { insert list; } Catch(DMLExceptiion dml) { String msg = ''; for(Object ob : list){ msg = msg + ob.Name + BR(); } //at the end of the for loop, the msg variable has a list of all names of the object where there is a new line break after each name //structure of sendEmail method is SendEmail(Subject, Body); Email.SendEmail ('Test', msg); }
All Answers
You can use htmlBody() method of SingleEmailMessage class. By this mehtod you can pass html content in htmlbody method.
SingleEmailMessage class contain method htmlBody() this method will solve your problem
I think "\n" should work for you, I remember using the same earlier with the setPlainTextBody()