+ Start a Discussion
Cameron SeitzCameron Seitz 

Compiling Error when Creating Apex Class for Batch

When I attempt to save my Apex Class I receive the error "Error: Compile Error: Unexpected token 'class timecardEndDateAudit implements Database.Batchable'. at line 3 column 8"
I can't seem to figure out what I'm missing here. 

gobal class timecardEndDateAudit implements Database.Batchable<sObject>,Database.Stateful{

global Database.QueryLocator start(Database.BatchableContext bc){

String query = 'SELECT jstcl__Placement__r.Name , Account_Executive__c , jstcl__Placement__r.Timecard_End_Date_Audit__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Week_Ending__c >= LAST_N_DAYS:14'

return Database.getQueryLocator(query);
global void execute(Database.BatchableContext bc,List<Placement>scope){

for (Placement Placements :scope){
Placements.Timecard_End_Date_Audit__c ='1';
}
update scope;
}
global void finish(Database.BatchableContext bc){}
}
Cameron SeitzCameron Seitz
I mispelled global when I copied it here but it's correct in my code
Sagar PatilSagar Patil
Hi Cameron,

I could see that you missed close curly brace after return Database.getQueryLocator(query); statement and colon at the end of query.

Try this,
 
global class timecardEndDateAudit implements Database.Batchable<sObject>,Database.Stateful{

global Database.QueryLocator start(Database.BatchableContext bc){

String query = 'SELECT jstcl__Placement__r.Name , Account_Executive__c , jstcl__Placement__r.Timecard_End_Date_Audit__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Week_Ending__c >= LAST_N_DAYS:14';

return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<Placement>scope){

for (Placement Placements :scope){
Placements.Timecard_End_Date_Audit__c ='1';
}
update scope;
}
global void finish(Database.BatchableContext bc){}
}

Kindly mark this as a best answer if it solves your problem.

Regards,
Sagar
Cameron SeitzCameron Seitz
I've corrected everything to the code below and am still receiving the compiling error
 
public class timecardEndDateAudit implements Database.Batchable<sObject>,Database.Stateful{

	public Database.QueryLocator start(Database.BatchableContext bc){
		String query = 'SELECT jstcl__Placement__r.Name , Account_Executive__c , jstcl__Placement__r.Timecard_End_Date_Audit__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Week_Ending__c >= LAST_N_DAYS:14';
		return Database.getQueryLocator(query);
	}
	
	public void execute(Database.BatchableContext bc,List<sObject>scope){
	
		for (Placement jstcl__TG_Timesheet__c : (List<jstcl__TG_Timesheet__c>) scope){
			Placements.Timecard_End_Date_Audit__c ='1';	
		}

		update scope;
	}

	
	public void finish(Database.BatchableContext bc){
	}
}

I did definitely miss those though so thank you! 
Sagar PatilSagar Patil
Which error you have recieved now? is it same or different?

It looks the variable name you have mentioned inside for loop in execute method is same as custom object which is confusing. Hope Timecard_End_Date_Audit__c is a custom field present on Placement object. Also i have noticed that Placement is custom object so please append __c in code.

global void execute(Database.BatchableContext bc,List<Placement__c>scope){
        for (Placement__c aa : (List<Placement__c >) scope){
                aa.Timecard_End_Date_Audit__c ='1';
           }
}
 
Cameron SeitzCameron Seitz
When I replace my execute section with yours I get "Error: Compile Error: Missing '<EOF>' at 'global' at line 14 column 4.". My goal in the execute section is for it to take the placement records that I previously queried and to edit the Timecard_End_Date_Audit field on those records to reflect '1'. 
Jay Parikh 36Jay Parikh 36
Hi -- Try this code and let me know if you need any help !!!1
global class timecardEndDateAudit implements Database.Batchable<sObject>,Database.Stateful
{

      global Database.QueryLocator start(Database.BatchableContext bc){

       String query = 'SELECT jstcl__Placement__r.Name , Account_Executive__c , jstcl__Placement__r.Timecard_End_Date_Audit__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Week_Ending__c >= LAST_N_DAYS:14'

        return Database.getQueryLocator(query);
global void execute(Database.BatchableContext bc,List<Placement>scope){
  list <Placement> pcupdate = new list <Placement> ();
for (Placement Placements :scope){
	if(Placements.Timecard_End_Date_Audit__c == null)
	{	
	 Placement pc = new Placement ();
	 pc.id = Placements.id;
     pc.Timecard_End_Date_Audit__c ='1';
	 pcupdate.add(pc);
	}
}
 DataBase.update(pcupdate,false);  
}
global void finish(Database.BatchableContext bc)
{
}
}
Briana L.Briana L.
You want to change everything from "public" to "global"
Ajay K DubediAjay K Dubedi
Hi Cameron,
Try this code:


global class timecardEndDateAudit implements Database.Batchable<sObject>,Database.Stateful{

   global Database.QueryLocator start(Database.BatchableContext bc){

      return Database.getQueryLocator([SELECT jstcl__Placement__r.Name , Account_Executive__c , jstcl__Placement__r.Timecard_End_Date_Audit__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Week_Ending__c >= LAST_N_DAYS:14]);
    }
   global void execute(Database.BatchableContext bc,List<sObject>scope){
 
      for (jstcl__TG_Timesheet__c jt : (List<jstcl__TG_Timesheet__c>) scope)){
        jt.jstcl__Placement__c.Timecard_End_Date_Audit__c ='1';
          }
      update scope;
    }

global void finish(Database.BatchableContext bc){}
}


Please mark this as Best Answer if you find this solution is helpful.

Thank You
Ajay Dubedi