Save and send generated PDF

41 views
Skip to first unread message

venkat gattamaneni

unread,
Feb 4, 2014, 9:46:18 AM2/4/14
to salesforce-p...@googlegroups.com
Any one have save and send gernerated PDF CODE. Thanks.


Thanks and Regards

Venkat Gattamaneni
ERMClouds.com

+91-9986113337

ven...@ermclouds.com

venkat.ga...@gmail.com

Skype: venkatforce

Service Cloud | Sales Cloud | Advanced Administrator | Administrator | Developer Certified

Cloud Computing Technologies
Salesforce.com |   Force.com Sites   |   Customer & Partner Portals   |   CastIron Cloud Integrations | Amazon Web Services 
| HTML5 & Web Technologies | NetSuite | SEO 

Narasimha

unread,
Feb 4, 2014, 9:58:07 AM2/4/14
to salesforce-p...@googlegroups.com
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 });
        }
    }



--
You received this message because you are subscribed to the Google Groups "salesforce professionals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salesforce-profess...@googlegroups.com.
To post to this group, send email to salesforce-p...@googlegroups.com.
Visit this group at http://groups.google.com/group/salesforce-professionals.
For more options, visit https://groups.google.com/groups/opt_out.



--

Thanks,

Venkata Narasimha Rao. Vutla

Salesforce.com Certified Force.com Developer 401, Administrator 201, Advanced Administrator 211, Salesforce.com Certified Service Cloud Consultant, and Advanced Salesforce.com Certified Force.com Developer 501



Cell - +91 - 9705898616
Reply all
Reply to author
Forward
0 new messages