Here I am going to show you, How to insert formatted data (table, colorful text etc) in rich text area field salesforce. We can directly use updated rich text area in our email templates without doing any extra code for email template.
Here is sample code.
Below code is for table:-
string table ='<p><span style=\"color: #2e6c80;\"><strong>Table Heading</strong></span>
</p>\r\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12px;\">\r\n<tbody>';
table+=createColumn('table column ame 1','Table column Value 1');
table+=createColumn('Your column Name 2','table column value 2');
public static string createColumn(string column,string value){
return '<tr>\r\n<td>'+column+'</td>\r\n<td tabindex=\"0\">\r\n<div>'+value+'</div>\r\n</td>\r\n</tr>';
}
Here is sample code.
//Heading for rich text area content.
string body='<h3 style=\"color: #2e6c80;\">your heading :</h3>\n
<ol style=\"list-style: none; font-size: 12px; line-height: 32px; \">\n';
body += '<li style=\"clear: both;\"><b>'+Your Label Name+' : </b> '+
yourValue.replaceAll(';',' , ') +'</li>';
body +='</ol>';
yourRichTextAreaField=body;
Below code is for table:-
string table ='<p><span style=\"color: #2e6c80;\"><strong>Table Heading</strong></span>
</p>\r\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:12px;\">\r\n<tbody>';
table+=createColumn('table column ame 1','Table column Value 1');
table+=createColumn('Your column Name 2','table column value 2');
table+='</tbody>\r\n</table>';public static string createColumn(string column,string value){
return '<tr>\r\n<td>'+column+'</td>\r\n<td tabindex=\"0\">\r\n<div>'+value+'</div>\r\n</td>\r\n</tr>';
}