You need to sign in to do that
Don't have an account?
Akis Athanasiadis
Export Scheduled Report in excel
I need to have a schedule report exported to excel and put it into a schedule and send it to specific e-mails.
I have already the report created.
I have used the following code:
global class Exporter implements System.Schedulable {
global void execute(SchedulableContext sc) {
ApexPages.PageReference report = new ApexPages.PageReference('/00O58000003m3Sa?csv=1');
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName('report.xls');
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[] { 'mplampla.com' } );
Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
}
}
although I don't see how i give this a schedule.
I guess that this reads the schedule that exists in the report and so the report is sent thourgh this code as an attachment in an email?
Can I also store the executable attachment directly to a path?
I have already the report created.
I have used the following code:
global class Exporter implements System.Schedulable {
global void execute(SchedulableContext sc) {
ApexPages.PageReference report = new ApexPages.PageReference('/00O58000003m3Sa?csv=1');
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName('report.xls');
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[] { 'mplampla.com' } );
Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
}
}
although I don't see how i give this a schedule.
I guess that this reads the schedule that exists in the report and so the report is sent thourgh this code as an attachment in an email?
Can I also store the executable attachment directly to a path?
All Answers
Run this code in anonymous window in developer console. This will schedule your class to run everyday. Thanks.
Hi Ravi,
I need to run schedule once or twice per week.So if i want to run a schedule every monday on a specific time,how do I set that?