[SalesForce] Class Error Unexpected token Global

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());
}
}

Best Answer

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());
   }

}
Related Topic