function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Naveen Reddy 8Naveen Reddy 8 

Unable to get reports as excel/CSV file in scheduled reports

Hi,
 I have created and scheduled daily and weekly reports for leads in my CRM. 
And able to get the mails daily and weekly for the reports.
The problem is report is sent as mail not excel or csv file attachments.
How to get scheduled reports as excel/csv file attchments in mails .
Any help is really appreciated.

Thanks,
Naveen.
Best Answer chosen by Naveen Reddy 8
KevinPKevinP
This isn't possible with the out of the box tools available to you. You can do this with either Apex code or trigger the execution of the report remotely with a scheduler like Cron. You can find out more information on how to do either here: https://developer.salesforce.com/forums/ForumsMain?id=906F00000008n0zIAA

All Answers

KevinPKevinP
This isn't possible with the out of the box tools available to you. You can do this with either Apex code or trigger the execution of the report remotely with a scheduler like Cron. You can find out more information on how to do either here: https://developer.salesforce.com/forums/ForumsMain?id=906F00000008n0zIAA
This was selected as the best answer
Naveen Reddy 8Naveen Reddy 8
Hi Kevin,
 If I run these code through Developer console I'm able to recieve attachment properly.
i.e.
User-added image

If I schedule this class I'm recieving the attachment as like this.
 User-added image
 
global class LeadReport3 implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O90000008euMX?csv=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('Leads.csv');
        attachment.setBody(Blob.valueof(report.getContent().toString()));
        attachment.setContentType('text/csv');
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setSubject('Lead Report');
        message.setPlainTextBody('The report is attached.');
        message.setToAddresses( new String[] { 'naveen.bpy@gmail.com' } );
        message.setCcAddresses(new String[] { 'naveen.catch@gmail.com'});
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        
    }
    }

Note: A report is there in my org with id 00O90000008euMX

Please help..

Thanks,
Naveen
DmonikaDmonika
plz we need a sloution of this.. We are also facing the same problem
PERFECTIONISTPERFECTIONIST
Hello Monika,

Hope you are doing well!

Will you able to schedule report in csv formate, if Yes, could you please let me know how you resolved your issue. so that it will help ful for all the of the SFDC Users.


Thanks,
RSATIS