You need to sign in to do that
Don't have an account?
Anto Hotelbeds
Case description in HTML when sending apex email
Hi,
I have a surely easy requirement but I cant manage to get it. I have my case, and I need to send an email (though Apex) with the case description (between other fields). I have my case description with line breaks as follows:
"Hello hello hello
And two two two
Three
Three"
I send the email with the following code:
String HTMLDesc=case2.Description.escapeHtml3(); mail.setToAddresses(toAddresses); mail.setSubject('YYYYYou have been involved in the XML Case #'+Case2.CaseNumber); mail.setHtmlBody('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><table><tr><td>You are receiving this e-mail because you have been added to the referenced XML Support case. If you wish to post a comment to the case, please respond to the unique email address provided for this case without modifying the subject. </td></tr></table><br><table style="width:100%;border-collapse: collapse;"><tr><td style="padding:5px 0;width:140px;border-bottom:1px solid #aaa;">Case Description:</td><td style="padding:5px 0;width:560px;border-bottom:1px solid #aaa;">'+HTMLDesc+'</td></tr><br><br>Regards, <br>'+UserInfo.getName()+'<br>Clients Integration Support <br>Hotelbeds<br><br></html>'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
But I am getting the case description in plain text as follows:
"Hello hello hello And two two two Three Three"
Thanks a lot!
Antonio
I solved the problem using:
HTMLDesc=case2.Description.replaceAll('\n', '<br/>');
Thanks a lot for your help!
Antonio
All Answers
Hi Antonio,
I tried this using trigger with samll changes and its working fine for me.
Try the following,
trigger SendEmailForCase on Case(after insert, after update) {
for (Case e : Trigger.new){
user u = [Select id,Name,profile.id,Email From user Where id=:e.ownerId];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String emailAddr = u.Email;
String HTMLDesc = e.Description;
String[] toAddresses = new String[] {emailAddr};
mail.setToAddresses(toAddresses);
mail.setSubject('YYYYYou have been involved in the XML Case #'+e.CaseNumber);
//This should be in a single line without linebreaking
mail.setHtmlBody('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><table><tr><td>You are receiving this e-mail because you have been added to the referenced XML Support case. If you wish to post a comment to the case, please respond to the unique email address provided for this case without modifying the subject. </td></tr></table><br><table style="width:100%;border-collapse: collapse;"><tr><td style="padding:5px 0;width:140px;border-bottom:1px solid #aaa;">Case Description:</td><td style="padding:5px 0;width:560px;border-bottom:1px solid #aaa;">'+HTMLDesc+'</td></tr><br><br>Regards, <br>'+UserInfo.getName()+'<br>Clients Integration Support <br>Hotelbeds<br><br></html>');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Hope this will help you...!
I solved the problem using:
HTMLDesc=case2.Description.replaceAll('\n', '<br/>');
Thanks a lot for your help!
Antonio