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
ChristineMcKayChristineMcKay 

Scheduled reports - Formatting/Running out of time slots - Solutions? Code? AppExchange?

Hi all,

I manage an org where the end users (~100) like tons of schedueld reports. Some of the users are older and not as willing to adopt. As a solution to this, I would like to have their reports scheduled so if they will not log in, they at least can have their reports emailed to them automatically. 

Problems with this:

* Formatting of the HTML report show in the email body is terrible... hardly any spacing between columns, text wrapping in columns, phone numebrs do not even appear on the same line at times.

* Running out of time slots to choose from. For security reasons, each user needs their own report because they need to be selected as the running user.

* Too many reports. Would like to be able to find a way to filter dynamically OR select multiple running users.

Is any of this possible? Has anyone else managed an org where scheduled reports became a nightmare? 

I am open to ANY solution. I would prefer code, or something I can do without involving any third parties, but I am open to implementing something from AppExchange as well.

PLEASE HELP! 
Prateek Singh SengarPrateek Singh Sengar
Hi Tiffany,
Can you please provide little bit more clarity on the reports that are schedule. Are there mulitple reports that needs to be scheduled for multiple users. If so how many unique reports are we talking about.
If the situation is that the number of reports are less however they need to be schedule for tons of users because of record visibility then may be we can create a batch class that will generate reports for each user and mail them.
ChristineMcKayChristineMcKay
Hi Prateek,

Currently I have three unique reports scheduled for each user. You are exactly right in the fact that they need to be scheduled and ran by different users due to record visibility. Could I create a batch class for each of these three unique reports? Do you have any sample code on writing a batch class? 

Thank you for your help!
Prateek Singh SengarPrateek Singh Sengar
Hi Tiffany,
You can try something like this. Although based on your particular scenario it might be bit more complicated.

1) create an VF page that will generate the report in csv format (the VF page will have with sharing controller to provide user specific record access)
2) Create an batch class and schedule it to send to the users.
 
global class Exporter implements System.Schedulable {
    global void execute(SchedulableContext sc) {
        ApexPages.PageReference report = new ApexPages.PageReference('/VFPAGE');
        Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
        attachment.setFileName('report.csv');
        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[] { 'email@email.com' } );
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
        
    }
}