Skip to content

Instantly share code, notes, and snippets.

@surajp
Created July 30, 2020 14:24
Show Gist options
  • Save surajp/ef7087b402dcc08517237f57ae2ea6c5 to your computer and use it in GitHub Desktop.
Save surajp/ef7087b402dcc08517237f57ae2ea6c5 to your computer and use it in GitHub Desktop.
global class Exporter implements System.Schedulable {
global void execute(SchedulableContext sc) {
ApexPages.PageReference report = new ApexPages.PageReference('/00O500000000000?csv=1');
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 protected]' } );
Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment