0

I am not get the tabular report body in the attached email ,could you please help me.

global class Exportertest implements Schedulable,Database.AllowsCallouts{
    global void execute(SchedulableContext sc) {
        DoExport();
    }

    @future(callout=true)
    public static void DoExport() {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O3N000000JYOwert?csv=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.csv');
       //attachment.setBody(Blob.valueof(report.getContent().toString()));

        attachment.setBody(report.getContent());

        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] { 'hsr@gmail.com' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
    }
}
0
public static void DoExport() {
    ApexPages.PageReference rept = new ApexPages.PageReference('/00O0K00000AwUifUAF?csv=1&isdtp=p1');
    List<Messaging.EmailFileAttachment> attnt = new list<Messaging.EmailFileAttachment>();
    Messaging.EmailFileAttachment attnt1=new Messaging.EmailFileAttachment();
   //attachment.setBody(Blob.valueof(report.getContent().toString()));
system.debug(Blob.valueof(rept.getContent().toString()));
    attnt1.setBody(Blob.valueof(rept.getContent().toString()));
attnt1.setFileName('report.csv');
    attnt1.setContentType('text/csv');

    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
    message.setFileAttachments(new Messaging.EmailFileAttachment[] { attnt1 } );
    message.setSubject('Report');

    message.setPlainTextBody('The report is attached.');
    message.setToAddresses( new String[] { 'hsr@gmail.com' } );
    Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
}
    this works for me


  • Please edit this answer to describe what the problem is and how you fixed it. "Code dump" answers typically generate a lot of back and forth and add less value for the community. – David Reed Nov 8 '19 at 0:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.