You need to sign in to do that
Don't have an account?
Luke Higgins 22
Batch class that flags object
I'm trying to write a batch class that queries for timesheets (jstcl__TG_Timesheet__c) that has its lookup related placement occur twice or more from the query, and then use the list of flagged duplicate timesheets to update a checkbox field on them. My thought was to go through the queried results, add them to a list and then iterate through that list in to see if they already have been anaylized in order to flag them as having the same related placement.
Here is the code:
Here is the code:
global class placementTimecardAuditFlag implements Database.Batchable<sObject>, Database.Stateful { List<jstcl__TG_Timesheet__c> query = [SELECT jstcl__Placement__r.Name FROM jstcl__TG_Timesheet__c WHERE jstcl__Placement__r.ts2__Status__c ='Active' AND jstcl__Week_Ending__c = LAST_N_DAYS:15 AND jstcl__Status__c = 'Pending']; List<jstcl__TG_Timesheet__c> myList = new List<jstcl__TG_Timesheet__c>(); List<jstcl__TG_Timesheet__c> myList2 = new List<jstcl__TG_Timesheet__c>(); global Database.QueryLocator start(Database.BatchableContext bc) { for(jstcl__TG_Timesheet__c item : query){ if(myList.contains(item)){ myList2.add(item); } else{myList.add(item);} } return Database.getQueryLocator('SELECT Id,Checkbox1__c FROM jstcl__TG_Timesheet__c WHERE jstcl__Placement__r.Name IN :myList2');} global void execute(Database.BatchableContext BC, List<jstcl__TG_Timesheet__c> a){ for(jstcl__TG_Timesheet__c b : a) { if(b.Checkbox1__c = True){ b.Checkbox1__c = False; } else{b.Checkbox1__c = True;}} update a; } global void finish(Database.BatchableContext BC){} }Thank you
Here's what I figured out to work.