You need to sign in to do that
Don't have an account?
Cameron 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){}
}
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){}
}
I could see that you missed close curly brace after return Database.getQueryLocator(query); statement and colon at the end of query.
Try this,
Kindly mark this as a best answer if it solves your problem.
Regards,
Sagar
I did definitely miss those though so thank you!
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';
}
}
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