You need to sign in to do that
Don't have an account?
Malik Butler 5
Batch job update
I have a bacth job that needs updated. I have some criteria that needs added. I have half of it but I'm not sure how to finish it. Here's the criteria:
Create batch to query all the service appointments where:
Set to ServiceAppointment.Status = “C” (Canceled)
And If ServiceAppointment.ParentRecordType = “Work Order”,
Then Set WorkOrder.Status = “C” (Canceled) where WorkOrder.ID = ServiceAppointment.ParentID
Create batch to query all the service appointments where:
- ServiceAppointment.Subject = “Reload” or “Pre-Trip report” or “Post-Trip report”
- and ServiceAppointment.Status = “O” (Open)
- and ServiceAppointment.ScheduledEnd less than Today
Set to ServiceAppointment.Status = “C” (Canceled)
And If ServiceAppointment.ParentRecordType = “Work Order”,
Then Set WorkOrder.Status = “C” (Canceled) where WorkOrder.ID = ServiceAppointment.ParentID
global class ServiceAppointmentCancel implements Database.Batchable<SObject>, Schedulable { global Database.QueryLocator start(Database.BatchableContext BC) { String subject = 'Reload,Pre-Trip report,Post-Trip report'; String status = 'O'; Date SchedEndTime = Date.today(); String query = 'SELECT Subject,Status,SchedEndTime FROM ServiceAppointment WHERE subject = :subject AND status = :status AND SchedEndTime < :SchedEndTime'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<ServiceAppointment> serviceAppointments) { // Loop to iterate over the service appointments for(ServiceAppointment service : serviceAppointments) { service.status = 'C'; } // Preforming the DML operation update serviceAppointments; } global void finish(Database.BatchableContext BC) { } global void execute(System.SchedulableContext SC) { Database.executeBatch(new ServiceAppointmentCancel(), 200); } }