Hi....
private static string generateHeaderPDFString(Account objAccount) {
String strOLIHPDF = '';
string pdfheaderImages='<table width="600" cellpadding="0" cellspacing="0" border="0"><tr><td><img width="90" src="
https://test.salesforce.com"></td></tr></table>';
string pdfAccountDetailsTab='<table width="600" cellpadding="0" cellspacing="0" style="margin:0px auto;" border="0"><tr>';
string pdfAccountDetailsTabTd='<td valign="top" style="padding:0px;" colspan="6"><div style=""><table border="0" cellpadding="0" cellspacing="0" style="margin:0px auto;width:500px"><tr valign="top"> <td colspan="4" style="font-size:10pt;"><table border="0"><tr valign="top"><td nowrap="true" style="font-size:9pt;"><br><span>'+objAccount.Name+'</span><br><span>'+objAccount.BillingStreet+'</span><br><span>'+objAccount.BillingCity+'</span>, <span>'+objAccount.BillingState+'</span>, <span>'+objAccount.BillingPostalCode+'</span><br> <span>'+objAccount.Phone+'</span><br><b>Account Number:</b> <span>'+objAccount.Account_Number__c+'</span><br><br></td></tr></table></td></tr></table></div><br/></td></tr></table>';
String oliStr = '<table width="600" cellpadding="0" cellspacing="0" style="margin:0px auto;" border="0"><tr><td style="font-weight:bold;padding-left:10px">Account</td><td style="padding-left:10px;font-weight:bold">Directory</td><td style="padding-left:10px;font-weight:bold"> Directory Edition</td><td style="padding-left:10px;font-weight:bold"> Primary Contact</td><td style="padding-left:10px;font-weight:bold"> Primary Contact Email Address</td><td style="padding-left:10px;font-weight:bold"> Letter Renewal Sequence</td></tr>';
String hLine = '<tr><td colspan="6"><hr/></td></tr></table>';
strOLIHPDF = pdfheaderImages+pdfAccountDetailsTab+pdfAccountDetailsTabTd+oliStr+hLine;
return strOLIHPDF;
}
private static string generateOLIPDFString(Order_Line_Items__c iterator) {
String strOLIPDF = '';
String oliDataStr = '<table width="600" cellpadding="0" cellspacing="0" style="margin:0px auto;" border="0"><tr>';
String oliDataStr1 = '<td style="font-weight:normal;padding-left:8px">'+
iterator.Account__r.Name+'</td><td style="padding-left:8px;font-weight:normal">'+
iterator.Directory__r.Name+'</td><td style="padding-left:8px;font-weight:normal" width="14%">'+
iterator.Directory_Edition__r.Name+'</td><td style="padding-left:8px;font-weight:normal" width="14%">'+
iterator.Billing_Contact__r.Name+'</td><td style="padding-left:8px;font-weight:normal" width="14%">'+iterator.Billing_Contact__r.Email+'</td><td style="padding-left:8px;font-weight:normal" width="14%">'+iterator.Account__r.Letter_Renewal_Sequence__c+'</td></tr></table>';
strOLIPDF = oliDataStr+oliDataStr1 ;
system.debug('*********LETTER RENWAL STRING GENERATION ***********'+strOLIPDF);
return strOLIPDF;
}
private static void sendEmail(map<Id, String> mapRenewalPDFString) {
for(Id conId : mapRenewalPDFString.keySet()) {
//Initializing for Sending Mails(Written Single because of in a loop)
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
//Initializing the Email Attachment
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName('Letter Renewal.pdf');
efa.setBody(Blob.toPDF(mapRenewalPDFString.get(conId)));
fileAttachments.add(efa);
email.setFileAttachments(fileAttachments);
email.setTargetObjectId(conId);
email.setTemplateId(Label.Letter_Renewal_Report_Template);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
}
}
}