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
Arash TeimoupoorArash Teimoupoor 

email larg report as csv attachment

I'm using the following to email my report as CSV but it just includes the first 2000 rowes in the csv file while my report has more than 50000 rowes. how can I solve this? thanks in advance:

global class Report implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/00O60000003XpO6?csv=1');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
        message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
        message.setPlainTextBody('test is attached.');
        message.setToAddresses( new String[] { '' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
Is this a joined report? AFAIK they are the only ones that have the 2000 limit when exporting. The other option is to use the analytics API to execute the report and then process the results yourself, although 50000 rows might cause an issue when producing a CSV attachment.

Arash TeimoupoorArash Teimoupoor
Bob, it's a multi object report for a custom object and activities, so I can't use dataloader or Jitterbit to export it, that's why I'm looking for a way to export this report as csv file and email it or put it on FTP on a Scheduled basis. but the apex just send the first 2000 rows as attachment to the email adress. 

i tried your code, how do i invoke the code from the anonymous window, and how do i check if its working properly or not