1

I am trying to dchedule an apex class for sending messages so i wrote this simple class :

global class ScheduleSendingReports implements Schedulable {
    public static id idcantact = '1201254';
    global void execute(SchedulableContext SC) {
        Sendemail2.sendEmail2(idcantact);
    }
}

but i get an error:

An error has occurred in the following section: [Exception, InvalidScheduledApexClass]. Salesforce.com has been notified of this error.

any ideas to solve the problem ?

here is the code of sendmail2 class

global class Sendemail2 {
    webservice static String sendEmail2(id idcantact) {
        ApexPages.PageReference report = null;
        List<Messaging.SingleEmailMessage> lstMails = new List<Messaging.SingleEmailMessage>();
        List<user> userss = [select id, name, Fontion__c, email from user where isactive=:true and (Fontion__c=:'Directeur général' or Fontion__c=:'Directeur général adjoint' or Fontion__c ='Directeur commercial' or Fontion__c ='DR' or Fontion__c='Directeur clientèle' or Fontion__c='Process manager')];
        for ( user us : userss ) {
            if ( us.Fontion__c == 'Directeur commercial' ) {
                report = new ApexPages.PageReference('/00Ob0000003ZspF?pn1=eq&pv1='+us.name+'&excel=1');
            }
            if ( us.Fontion__c == 'Directeur clientèle' || us.Fontion__c == 'DR' ) {
                report = new ApexPages.PageReference('/00Ob0000003ZspF?pn2=eq&pv2='+us.name+'&excel=1');
            }
            if ( us.Fontion__c == 'Process manager' ) {
                report = new ApexPages.PageReference('/00Ob0000003ZspF?pn3=eq&pv3='+us.name+'&excel=1');
            }
            if ( us.Fontion__c == 'Directeur général' || us.Fontion__c == 'Directeur général adjoint' ) {
                report = new ApexPages.PageReference('/00Ob0000003ZspF?excel=1');
            }

            Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
            attachment.setFileName('report.xls');
            attachment.setBody(report.getContent());
            attachment.setContentType('application/vnd.ms-excel');

            Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
            message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
            message.setSubject('Report');
            message.setPlainTextBody('Bonjour, Ci-joint le rapport Effectif Hebdo, Bonne réception');
            message.setToAddresses( new String[] { 'xxxxx@xxxxxx'} );
            lstMails.add(message);
        }
        Messaging.sendEmail(lstMails);
        return string.valueof(lstMails.size());
    }
}

1 Answer 1

0

Try changing

public static id idcantact = '1201254';

to

Global static id idcantact = '1201254';

1
  • Also try changing data type from Id to String global static String idcantact = '1201254'; Feb 25, 2016 at 16:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .