You need to sign in to do that
Don't have an account?
Why does getContent() not work when it is schedule?
I am working on developer console.
I get mail with attachment when I try to execute this: SendingReportTest.execute(null);
But I don't get the attachment in the mail I try to execute this: System.schedule('JOB1', '0 0 * * * ?', new SendingReportTest());
Attachment is empty.
My schedulable class is following:
global class SendingReportTest implements Schedulable{
public static void execute(SchedulableContext s){
sendMail();
}
public static void sendMail() {
try{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
ApexPages.PageReference report = new ApexPages.PageReference('/00Og0000000JSg4?excel=1&exp=1&enc=iso-8859-9');
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName('report.xls');
attachment.setBody(report.getContent());
attachment.setContentType('text/csv');
mail.setFileAttachments(new Messaging.EmailFileAttachment[]{ attachment });
mail.setToAddresses(new String[]{test@email'});
mail.setSubject('konu');
mail.setPlainTextBody('text');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}catch(Exception e){system.debug(e);}
}
}
Hi Mustafa,
This is suggested as one of the best practises for using Apex Scheduler:
reference:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm
Yes, I've seen this. What should I do for sending a report xls file as attachment? Is there a way to do it ?