I'm running a batch class over the Timesheet object and for the timesheets that meet the criteria, I want to update the related Contact record.
I have a jstcl__TG_Timesheet__c object with a field jstcl__Consultant__c relating jstcl__TG_Timesheet__c to the Contact object. I'm trying to run a batch class over the timesheets and for the ones that meet the criteria, I want to update the Previous_Timesheet_Status__c field on the related Contact record. What I have now runs successfully, however it doesn't actually update the field.
public class batchClass implements Database.Batchable<sObject>{
public Database.QueryLocator start(Database.BatchableContext bc) {
String query = 'SELECT Id, jstcl__Consultant__r.Previous_Timesheet_Status__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Placement__r.ts2__Status__c =\'Active\' AND jstcl__Placement__r.VMS__c = \'\' AND jstcl__Week_Ending__c = LAST_N_DAYS:4 AND jstcl__Status__c = \'Pending\'';
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<jstcl__TG_Timesheet__c> a){
for(jstcl__TG_Timesheet__c b : a){
b.jstcl__Consultant__r.Previous_Timesheet_Status__c = 'Pending';
}
update a;
}
public void finish(Database.BatchableContext BC){}
}