Created
July 30, 2020 14:24
-
-
Save surajp/ef7087b402dcc08517237f57ae2ea6c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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