You need to sign in to do that
Don't have an account?
Manju053
Email Report with csv attachment
Hello Developers
My Requirement is that Reports must be sent through email with csv attachments, i have refered several blogs,
Basically Report needs to go in email with csv format, i have designed a apex class, but i dont know how to excute it in ananomus window
My Requirement is that Reports must be sent through email with csv attachments, i have refered several blogs,
Basically Report needs to go in email with csv format, i have designed a apex class, but i dont know how to excute it in ananomus window
global class sendreport implements System.Schedulable { global void execute(SchedulableContext sc) { ApexPages.PageReference report = new ApexPages.PageReference('00O2w000002RDbUEAW'); //this id of the report Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment(); attachment.setFileName('report.xls'); 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[] { 'manjunath.s@proseraa.com' } ); Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } ); } }Any help please?
Please find below details.
Go to Setup --> Open Developer Console.
Select "Debug" tab --> Open Execute Anonymous Window
In this window, type
Database.executeBatch(new MyClass());
Please make sure to replace MyClass with the apex batch class name that you have written/ want to execute.
Also review below article on how to execute batch Apex from Developer Console
https://help.salesforce.com/articleView?id=000328480&language=en_US&type=1&mode=1
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar
Thanks, My Original Question was report should be sent from salesforce with report attachments in csv format, i tried from the above code
but its not working, can you guide me please or give any suggestion
I tried from the several links but stil it did not get resolved,
Link - https://www.forcetalks.com/salesforce-topic/how-to-send-reports-via-email-to-a-group-of-users-on-an-hourly-basis/
Link - https://salesforce.stackexchange.com/questions/283865/convert-report-data-to-csv-format-and-send-attachment-in-mail-using-apex
i am getting an email with attach but i am not able to see the data inside the atachment
This is what i am getting
This is what i am expecting