Why we use ? :
In the many case we need to fetch email body of template with filled values of variables.
========================================
Apex Class Code :
Messaging.SingleEmailMessage mail ;
//--------- Html Body Fetching start here ----------
Savepoint sp = Database.setSavepoint();
mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(<CONTACT ID>);
mail.setTemplateId(<TEMPLATE ID>);
String body = '';
Boolean isTextTemp ;
try{
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
body += '<html>';
body += '<Body>';
if(EMAILTEMPLATEOBJECT.TemplateType.equalsIgnoreCase('text')){
body = mail.getPlainTextBody();
}else{
isTextTemp = false;
body += mail.getHtmlBody();
body = body.replace('<meta charset="utf-8">','').replace('<br>','<br/>');
body += '</body>';
}
body += '</html>';
System.debug('--------HTML BODY WITH VALUES : '+body);
Database.rollback(sp);
}Catch(Exception e){
Database.rollback(sp);
}
//--------- Html Body Fetching ending here ----------
=====================================
Note : It only allows to fetch 10 template body at a time . like in loop.
Solution : For this we can use a future method.