+ Start a Discussion
Cameron SeitzCameron Seitz 

Scheduled Apex Batch Class - Logically Editing Placements

I currently am working on creating a Scheduled Apex Batch Class that pulls all jstcl__Placement__r.Name that exist on Timesheet__C that currently exceed 14 days since they have had time entered AND jstcl__Placement__r.ts2__Status__c = 'Active'. These are related objects that have some field relationships that I'm using.
It then takes that list of Placement Names from the Timesheet and the execute portion of the batch class needs to determine if there are duplicates within that list and + 1 to the placement.TimecardEnddateAudit__c field (picklist) of any duplicate record returned. What I have adds +1 to ALL the returned placements which isn't quite there. (or maybe that's entirely wrong too) Here is what I have so far. Any help is much appreciated. Appologies if my explaination is rough. 
 
global class timecardEndDateAudit implements Database.Batchable<sObject>, Database.Stateful {

  global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'SELECT jstcl__Placement__r.Name, Primary_Recruiter__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Placement__r.ts2__Status__c = \'Active\' AND jstcl__Week_Ending__c = LAST_N_DAYS:14 AND (jstcl__Status__c = \'Pending\')';
        return Database.getQueryLocator(query);
  }
  
  global void execute(Database.BatchableContext BC, List<sObject> placements){
        for (ts2__Placement__c placement : (List<ts2__Placement__c>) placements) {

            placement.TimecardEnddateAudit__c = placement.TimecardEnddateAudit__c + 1;
        }
       
        update placements;
  }
  global void finish(Database.BatchableContext BC){ }
}

 
Manj_SFDCManj_SFDC
Hi Cameron, 
are you trying figure out how to find duplicates before adding 1 to them ?
Cameron SeitzCameron Seitz
Yes. I'm trying to look at the list that the query returns and add 1 to anything that is a duplicate.