Activity Forums Salesforce® Discussions How to convert report in to PDF in Salesforce Apex class?

  • Mohit

    Member
    September 8, 2016 at 5:38 am

    Hi Tanu,

    It is not possible to convert report into PDF, but  in place of this you can create visualforce page same as report and schedule the visualforce page by using the code:
    public class EmailReport implements Schedulable {
    public void execute(SchedulableContext sc) {
    List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
    attach.setContentType('application/pdf');
    attach.setFileName('Report.pdf');
    pagereference Pg = Page.PDFPage;
    Blob body = pg.getcontentAsPdf();
    attach.Body = body;
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setToAddresses(new String[] { '[email protected]' });
    mail.setSubject('PDF Generation');
    mail.setHtmlBody('PFA');
    mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
    mails.add(mail);

    if(!mails.isEmpty()) {
    Messaging.SendEmail(mails);
    }
    }

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos