1

I am trying to include a custom action on future run reports to automatically export the csv content with the report scheduled. I have had success with sending the email in this way, but am encountering a problem when setting the attachment.

public class MyReportNotification implements Reports.NotificationAction{

    public void execute(Reports.NotificationActionContext context){

    Reports.ReportInstance c = context.getReportInstance();

    Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
    attachment.setFileName('report.csv');
    attachment.setBody(c);
    attachment.setContentType('text/csv');

    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
    message.setSubject('Your report is ready to review!');
    message.setPlainTextBody('The report is attached.');
    message.setToAddresses( new String[] { 'myemail@mail.com' } );
    message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
    Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );


}


}

On the message.setbody portion I am getting incorrect signature error. How can I modify this code to compile and correctly send the csv attachment?

  • I was able to export csv by converting the content to "blob" and then to "string". Upon successful send, I am notified of an error and the future run subscription is then made inactive requiring the user to reactivate. The desired content is correctly formatted in CSV, but further review is required to identify current issue. I will post code and test upon completion, but suggestions are always welcome =). – JoshuaWS Jul 22 '16 at 0:46
0

haven't tried it yet but i am assuming this can be done by ApexPages.PageReference by passing in the report id

c.getReportId(); 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();

see more detail here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.