You need to sign in to do that
Don't have an account?
Sam Satterfield
Apex Trigger to call Apex Class that send an email w/ attached csv report
I was initially, and still am, trying to schedule an Apex class to send this; but quickly realised that ".getContent()" wouldn't let me. I changed tactics to have it send via trigger, that called the class, and would then send the email w/ csv attached. I would then either schedule a class to update the object tied to the trigger, or a workflow to update it.
unfortunatly, the report it send looks like this:
I've figured that something about going through a trigger does this; as a button works just fine.
I will include my code below, and I appreciate any help. Thanks.
Trigger:
unfortunatly, the report it send looks like this:
I've figured that something about going through a trigger does this; as a button works just fine.
I will include my code below, and I appreciate any help. Thanks.
Trigger:
trigger Call4Health_Export on Analytics__c (before Update) { For(Analytics__c Ana: Trigger.new) {Call4Health_Export.Call4Health_Export(Ana.Id);} }Class:
global class Call4Health_Export implements Database.AllowsCallouts{ @future(callout=true) webservice static void Call4Health_Export(Id recId){ if(recId!=null) { ApexPages.PageReference report = new ApexPages.PageReference('/00O19000000VSV2?csv=1'); Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment(); attachment.setFileName('report.csv'); attachment.setBody(Blob.valueof(report.getContent().toString())); attachment.setContentType('text/csv'); Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage(); message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } ); message.setSubject('Lead Report'); message.setPlainTextBody('The report is attached.'); message.setToAddresses( new String[] { 'ssatterfield@femwell.com' } ); message.setCcAddresses(new String[] { 'ssatterfield@femwell.com'}); Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } ); }}}
Please share your VF page code also.
Thanks,
Vishal
Like this:
Clint