You need to sign in to do that
Don't have an account?
Hampton
Need Help Scheduling Batch Process
Good Morning:
I have the following Apex Class which converts records froma temporary staging custom object over to new records in another custom object. I am having issues getting the class set up to schedule this run. Any help is appreciated.
The issue in the scheduleble class is in
Penetration_Summary__c convertBatch = new Penetration_Summary__c(query);
Hampton
global class PenetrationSummaryConversion implements Database.Batchable<sObject>{ public string Query; public Penetration_Summary__c penSum; public List<Penetration_Summary__c> insertPenSumList = new List<Penetration_Summary__c>(); List<Group> QueueList = new List <Group>(); Map<String,Id> QueueMap = new Map<String,Id>(); List<Penetration_Staging_Records__c> addStagingList = new List<Penetration_Staging_Records__c>(); List<Penetration_Staging_Records__c> deleteStagingList = new List<Penetration_Staging_Records__c>(); global Database.querylocator start(Database.BatchableContext BC) { Query = 'Select Name, Id, OwnerId, LastModifiedDate, Release__c, CBW_Rev__c, CBW_Subs__c, Copper_CBAD_Rev__c, Copper_CBAD_Subs__c,'+ 'Copper_Voice_Rev__c, Copper_Voice_Subs__c, DSL_Rev__c, DSL_Subs__c, Fiber_CBAD_Rev__c,'+ 'Fiber_CBAD_Subs__c, Fiber_Internet_Rev__c, Fiber_Internet_Subs__c, Fiber_Voice_Rev__c, Fiber_Voice_Subs__c,'+ 'Premium_Speed_Rev__c, Premium_Speed_Subs__c, Units__c, Video_Subs__c, Video_Rev__c,'+ ' From Penetration_Staging_Records__c' + ' Where Batch_Processed__c=false'; return Database.getQueryLocator(Query); } global void execute(Database.BatchableContext BC, List<sObject> scope) { QueueList=[Select Id, Name, DeveloperName, Type from Group where Type = 'Queue']; for(Group qObj:QueueList){ QueueMap.put( qobj.Name, qobj.Id); } for(sObject s: scope) { Penetration_Staging_Records__c tempPenRecords = (Penetration_Staging_Records__c)s; if(tempPenRecords.LastModifiedDate < System.now() || Test.isRunningTest()) addStagingList.add(tempPenRecords); } for(Penetration_Staging_Records__c tempRecord : addStagingList){ penSum = new Penetration_Summary__c(); penSum.Copper_Voice_Subs__c = tempRecord.Copper_Voice_Subs__c; penSum.Copper_CBAD_Subs__c = tempRecord.Copper_CBAD_Subs__c; penSum.DSL_Subs__c = tempRecord.DSL_Subs__c; penSum.Premium_Speed_Subs__c = tempRecord.Premium_Speed_Subs__c; penSum.Fiber_Voice_Subs__c = tempRecord.Fiber_Voice_Subs__c; penSum.Fiber_CBAD_Subs__c = tempRecord.Fiber_CBAD_Subs__c; penSum.Fiber_Internet_Subs__c = tempRecord.Fiber_Internet_Subs__c; penSum.Video_Subs__c = tempRecord.Video_Subs__c; penSum.CBW_Subs__c = tempRecord.CBW_Subs__c; penSum.Copper_Voice_Rev__c = tempRecord.Copper_Voice_Rev__c; penSum.Copper_CBAD_Rev__c = tempRecord.Copper_CBAD_Rev__c; penSum.DSL_Rev__c = tempRecord.DSL_Rev__c; penSum.Premium_Speed_Rev__c = tempRecord.Premium_Speed_Rev__c; penSum.Fiber_Voice_Rev__c = tempRecord.Fiber_Voice_Rev__c; penSum.Fiber_CBAD_Rev__c = tempRecord.Fiber_CBAD_Rev__c; penSum.Fiber_Internet_Rev__c = tempRecord.Fiber_Internet_Rev__c; penSum.Video_Rev__c = tempRecord.Video_Rev__c; penSum.CBW_Rev__c = tempRecord.CBW_Rev__c; penSum.Units__c = tempRecord.Units__c; penSum.Name = tempRecord.Release__c; insertPenSumList .add(penSum); deleteStagingList.add(tempRecord); } insert insertPenSumList; delete deleteStagingList; } global void finish(Database.BatchableContext BC) { } }
global class PenetrationSummaryConversionScheduled implements Schedulable{ global void execute(SchedulableContext sc){ String query = 'Select Name, Id, OwnerId, LastModifiedDate, Release__c, CBW_Rev__c, CBW_Subs__c, Copper_CBAD_Rev__c, Copper_CBAD_Subs__c,'+ 'Copper_Voice_Rev__c, Copper_Voice_Subs__c, DSL_Rev__c, DSL_Subs__c, Fiber_CBAD_Rev__c,'+ 'Fiber_CBAD_Subs__c, Fiber_Internet_Rev__c, Fiber_Internet_Subs__c, Fiber_Voice_Rev__c, Fiber_Voice_Subs__c,'+ 'Premium_Speed_Rev__c, Premium_Speed_Subs__c, Units__c, Video_Subs__c, Video_Rev__c,'+ ' From Penetration_Staging_Records__c' + ' Where Batch_Processed__c=false'; Penetration_Summary__c convertBatch = new Penetration_Summary__c(query); Id BatchProcessId = Database.ExecuteBatch(convertBatch); } }
Hampton,
Try this:
All Answers
Hampton,
Try this:
Thanks Ram. That seemed to do it.
I have never written a test class for a batch process...any guidance you can give me on that?
Thanks,
Hampton
Hampton,
Try something like this