• Arif Syed
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello,
I have an Apex class that generates a CSV file.

global class AAAExporterCSV implements System.Schedulable {
global void execute(SchedulableContext sc) {
List<case> acclist = [Select casenumber,subject, accountid from case where closeddate=TODAY];
string header = 'Id, Subject,Account, '+'\n';
string finalstr = header ;
for(case a: acclist)
{
   string recordString = a.casenumber + ',' + a.subject+ ',' + a.accountid +'\n';
   finalstr = finalstr + recordString;
}
Messaging.EmailFileAttachment csvAttc = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(finalstr);
string csvname= 'cases.csv';
csvAttc.setFileName(csvname);
csvAttc.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] toAddresses = new list<string> {'v.veve@veve.com'};
String subject = 'Report CSV';
email.setSubject(subject);
email.setToAddresses( toAddresses );
email.setPlainTextBody('The Merchandise report is attached here.');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvAttc});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
  }
}

I wonder how do I put this CSV (cases.csv) within a ZIP and to send an email.
It is possible to do in the same class?

It's correct: ... where closeddate=TODAY ???
Thank you,