function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Silpi Roy 19Silpi Roy 19 

Send Email with schedulerclass

I want to send a single  email with multiple attachment using scheduler class.But email is not trigerring for the same.
global class SendEmailReports implements System.Schedulable  {
    global void execute(SchedulableContext sc) {
        SendEmail();

    }

    //Public String subject { get; set; }
   // public String body { get; set; }
    //private final Report rep;
    
         
     @future(callout=true)
   
    public static void sendEmail() {


 
      list<Report>  rep = [SELECT id, name FROM Report WHERE ownerId IN (
    SELECT ID FROM Folder WHERE Id='00l0C000000MJKvQAO')];
    }



    public PageReference send() {
        // Define the email 
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); 
        // Reference the attachment page and pass in the Report ID 
        Integer numAtts=[SELECT count() FROM attachment WHERE parentId=:ApexPages.currentPage().getParameters().get('Id')];
        system.debug('Number of Attachments Atts = '+ numAtts);
        List<Attachment> allAttachment = new List<Attachment>();
        allAttachment = [SELECT Id, Name, ContentType, Body FROM Attachment WHERE parentid =:ApexPages.currentPage().getParameters().get('Id')];
        List<Messaging.Emailfileattachment> efaList = new List<Messaging.Emailfileattachment>();
     
        // try{ 
        if(numAtts > 0){
                for (Integer i = 0; i < numAtts; i++){
                    system.debug(allAttachment[i].Name);
            Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();            
            efa.setFileName(allAttachment[i].Name);
                    efa.setBody(allAttachment[i].Body);
                    efa.setContentType('text/csv');
            efaList.add( efa );
                }
        }
         
        
      String[] toAddresses = new String[] {'silpi.roy@atos.net'};

       email.setToAddresses(toAddresses);


        // Sets the paramaters of the email 
        
       // email.setFileAttachments(email_attachments);
        email.setPlainTextBody('The report is attached.');
        //Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
    
        
        
        

       
        //email.setFileAttachments(new Messaging.EmailFileAttachment[] {List<email>()});
        if(numAtts > 0){
           email.setFileAttachments(efaList );
        }
         
        // Sends the email 
        Messaging.SendEmailResult [] r = 
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});   
        return null;
    }
}

Please help
AbhishekAbhishek (Salesforce Developers) 
Hi Silpi,

Try the code and suggestions as mentioned in the below article,

https://developer.salesforce.com/forums/?id=906F0000000BancIAC

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.
Silpi Roy 19Silpi Roy 19
I have checked it but the problem here is my requirement is single email with multiple report attachment.