• Prasanth Krishna 10
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi ,

 

I have created a Batch class ,in which i m calling a visual force page which is rendred as PDF.

i m attaching it to mail. but content is not displayed.  I tried both getContent() and getContentAsPDF().

In get content it gives me error that Email Attachment was not correctly decoded and in getContentAsPDF() it gives a blank PDF.

 

 

Code -:

                            PageReference newPage = Page.SendInvoice;
                            newPage.getParameters().put('id',o.id);
                           
                            Blob blobFormPDF = null;
                            try {                              
                              blobFormPDF = newPage.getContent();  
                            } catch (VisualforceException e) {
                              blobFormPDF = Blob.valueOf('Some Text');
                            }                              
                            system.debug('---------blobFormPDF'+blobFormPDF);                        
                            Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
                            attach.setContentType('application/pdf');
                            attach.setFileName(o.Name+ '.pdf');
                            attach.setInline(false);
                            attach.setBody(blobFormPDF);               
                            
                            Messaging.Singleemailmessage mail= new Messaging.Singleemailmessage();                          
                            list<string>maillist = new list<string>();
                            maillist.add(c.email);
                            mail.setSubject('Invoice');
                            
                            mail.setPlainTextBody('Please find Attached Invoice');
                            mail.setToAddresses(maillist);
                            mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });                       
                            Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});   

 

How can i get the content in mail as attachment?

 

Thanks

Shailu

 

  • January 31, 2012
  • Like
  • 0