You need to sign in to do that
Don't have an account?
Srinu
Report in an email with CSV attachment
Hello,
We have few reports in place and whenever user runs they are recieving the report details in email body.
Can we send the details as an attachment?
Any suggestions how can we achieve this functionality by using any custom code?
Thanks,
Srinu
We have few reports in place and whenever user runs they are recieving the report details in email body.
Can we send the details as an attachment?
Any suggestions how can we achieve this functionality by using any custom code?
Thanks,
Srinu
this is an age old issue with salesforce.
Please check this Idea Exchange URL
https://success.salesforce.com/ideaView?id=08730000000Brb6AAC#
If you are ok with a thridparty solution. Please use
http://www.cloud4j.com/report-builder.html
Regards
Isidore
Below is the code sample that will create a CSV File in Apex.
Follow these steps which may help you.
1 . Create a batch class and write your custom logic to create CSV File.
String generatedCSVFile =”;
List<String> queryFields = new List<String>{‘Id’,’Type’,’Status’};
String fileRow = ”;
for(Account company: [select id,type,status from account limit 1000]){
fileRow = ”;
fileRow = fileRow +’,’+ company.Id;
fileRow = fileRow +’,’+ company.Type;
fileRow = fileRow.replaceFirst(‘,’,”);
generatedCSVFile = generatedCSVFile + fileRow + ‘\n’;
}
Messaging.EmailFileAttachment csvAttachment = new Messaging.EmailFileAttachment();
Blob csvBlob = blob.valueOf(generatedCSVFile);
String csvName = ‘company details which doesn’t have members.csv’;
csvAttachment.setFileName(csvName);
csvAttachment.setBody(csvBlob);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{‘Your Email Id’};
String subject = ‘company details which doesn’t have members CSV’;
email.setSubject(subject);
email.setToAddresses(toAddresses);
email.setPlainTextBody(‘company details which doesn’t have members CSV’);
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttachment});
Messaging.SendEmailResult[] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
Mark it as answer if it really helps you.
Thanks
Manoj S
You can send an email with the report as attachment in Excel format with the following code :