I am getting an error like "Argument 1 cannot be null" while running this batch apex Batchupdate_Montly_DepthTracker. Please note this batch runs on result sets returned from a scheduled apex.
Assumption: Is it because I am running the batch apex class without running the scheduled apex and the result sets are not returned?
Please find class- Batchupdate_Montly_DepthTracker
global class Batchupdate_Montly_DepthTracker implements Database.Batchable<sObject> {
public String query;
// Record types for Deapth Tracker
private String readonlyRecordtype = 'OAPI_HOS_Depth Tracker_Realonly';
private String FirstdayRecordtype = 'OAPI_HOS_Depth Tracker_FirstDay';
private String DefaultRecordtype = 'FutureMonth';
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
list<Depth_Tracker_OAPI__c> dts = new list<Depth_Tracker_OAPI__c>();
Map<String,Id> recordtypeforEndoftheMonth = new Map<String,Id>();
//Getting the Record types for Depth Tracker object
for(RecordType rect: [SELECT Id,Name FROM RecordType WHERE SobjectType = 'Depth_Tracker_OAPI__c']){
recordtypeforEndoftheMonth.put(rect.name.touppercase(), rect.Id);
}
Date todaydate = Date.TODAY();
for(sObject s : scope){Depth_Tracker_OAPI__c dt = (Depth_Tracker_OAPI__c)s;
//For past Depth Trackers
if( dt.End_Date_OAPI__c.isSameDay(todaydate) || dt.End_Date_OAPI__c < todaydate ) {
dt.RecordTypeId = recordtypeforEndoftheMonth.get(readonlyRecordtype.toUpperCase());
dt.Active_OAPI__c = false;
dts.add(dt);
}
//For Depth Trackers for current month
else if(dt.Start_Date_OAPI__c.Month() == todaydate.month() && dt.Start_Date_OAPI__c.year() == todaydate.year() ){
dt.RecordTypeId = recordtypeforEndoftheMonth.get(FirstdayRecordtype.toUpperCase());
dt.Active_OAPI__c = true;
dts.add(dt);
}
//Future Depth Trackers
else{
dt.RecordTypeId = recordtypeforEndoftheMonth.get(DefaultRecordtype.toUppercase());
dt.Active_OAPI__c = true;
dts.add(dt);
}
}
try{
//update Contcts;
list<Database.Saveresult> sr = database.Update(dts);
system.debug('Saveresult' + sr);
Set<Id> scRows;
if(sr != null) {
scRows = new Set<Id>();
for(Database.SaveResult r : sr) {
if(r.isSuccess() == false) {
scRows.add(r.getId());
}
}
system.debug('Update failed for Depth Tracker: '+ scRows );
}
}
catch(DMLException ex){
System.debug(LoggingLevel.ERROR,'Error while trying to updating Depth Trackers. ' +ex.getStackTraceString());
}
//Update dts;
}
global void finish(Database.BatchableContext BC){
}
}
The scheduled batch code is as below
global class scheduledBatchableForDepthTrackerLock implements Schedulable {
global void execute(SchedulableContext sc) {
Batchupdate_Montly_DepthTracker dtBatch = new Batchupdate_Montly_DepthTracker();
dtBatch.query ='SELECT Id, End_Date_OAPI__c, Start_Date_OAPI__c, RecordTypeId FROM Depth_Tracker_OAPI__c';
database.executebatch(dtBatch,50);
Batchupdate_Montly_HCPDepthTracker HCPdtBatch = new Batchupdate_Montly_HCPDepthTracker();
HCPdtBatch.query = 'SELECT Id, End_Date_OAPI__c, Start_Date_OAPI__c, RecordTypeId FROM HCP_Depth_Tracker_OAPI__c';
database.executebatch(HCPdtBatch,50);
}
}