2

I need some help, I have created the following (see below) However I am getting the following error : Error:

Compile Error: unexpected token: global at line 28 column 0

I do not understand why I am getting this error message ?

global class batchELQA_Delete implements Database.Batchable<ELQA_Marketing_Activity__c>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'Select Id FROM ELQA_Marketing_Activity__c WHERE CreatedDate < LAST_N_DAYS:180';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<ELQA_Marketing_Activity__c> scope)
    {
         delete scope;
         DataBase.emptyRecycleBin(scope);  
    }   
    global void finish(Database.BatchableContext BC){}     

}

// to schedule this to run everyday create a scheduled class:
//  This will cause the above class to run.   
global class SchedularForBatchApex implements Schedulable {

   global void execute(SchedulableContext sc) {
      ID BatchId = Database.executeBatch(new batchELQA_Delete(), 2000);
   } 

   Public static void SchedulerMethod() {
      string con_exp= ’0 0 1 * * ?’;
      System.schedule(‘batchELQA_Delete’, con_exp, new SchedularForBatchApex());
}
}
6

You can't have two classes in the same file. Instead, you can write it like this:

global class batchELQA_Delete implements Database.Batchable<SObject>, Schedulable {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'Select Id FROM ELQA_Marketing_Activity__c WHERE CreatedDate < LAST_N_DAYS:180';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<SObject> scope) {
         delete scope;
         DataBase.emptyRecycleBin(scope);  
    }

    global void finish(Database.BatchableContext BC){

    }

   global void execute(SchedulableContext sc) {
      ID BatchId = Database.executeBatch(new batchELQA_Delete(), 2000);
   }

   Public static void SchedulerMethod() {
      string con_exp= '0 0 1 * * ?';
      System.schedule('batchELQA_Delete', con_exp, new batchELQA_Delete());
   }

}
7
  • Hi SFDCFOX I get the following Error: Compile Error: line 23:22 no viable alternative at character '’' at line 23 column 22 When pasting the whole code into an apex clas. MPHh :( – Masond3 Jun 2 '14 at 14:21
  • Masond3, try changing the quotes around the con_exp from ’ to '. – Samuel De Rycke Jun 2 '14 at 15:07
  • HI Samuel De Rycke, i changed the quotations from ’0 0 1 * * ?’ to '0 0 1 * * ?' and also around 'batchELQA_Delete', but i now get the following error Compile Error: Invalid type: SchedularForBatchApex at line 24 column 56 – Masond3 Jun 2 '14 at 15:18
  • I'll check the code again. I only did a copy paste. – sfdcfox Jun 2 '14 at 15:32
  • Those quotes are wrong. Replace them with '. – sfdcfox Jun 2 '14 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.