I have a batch apex class in production that deals with custom objects Call2_vod__c and Hcp_Depth_Tracker. Finds out number of calls with same Account field and Territory field value and updates the number in Total_Actual_Calls_Month_OAPI__c field of Hcp_Depth_Tracker. It is working for some records not for the rest though those abide by all criteria set in the apex class. Please note it is called from a scheduled class operating on records with batch size 50.Is that reason for partial updates? If not then please let me know the case.
Apex Class snippet for update:
for(sObject s : scope)
{
HCP_Depth_Tracker_OAPI__c dt = (HCP_Depth_Tracker_OAPI__c)s;
if(HcpCallMap.get(dt.HCP_Account_OAPI__c) != null)
{
list<Call2_vod__c> calList = HcpCallMap.get(dt.HCP_Account_OAPI__c);
If( calList.size()> 0)
{
numCalls = 0;
for(Call2_vod__c cal: calList)
{
If(cal.CreatedBy.Primary_Territory_vod__c == dt.Depth_Tracker_OAPI__r.Territory_OAPI__c && (cal.Call_Date_vod__c >= dt.Start_Date_OAPI__c && cal.Call_Date_vod__c <= dt.End_Date_OAPI__c))
{
numCalls = numCalls + 1;
}
}
dt.Total_Actual_Calls_Month_OAPI__c = numCalls;
dts.add(dt);
}
}
try{
//update Contcts;
list<Database.Saveresult> sr = database.Update(dts);
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('Failed HCP Call Accrual rows '+ scRows );
}
}
catch(DMLException ex){
System.debug(LoggingLevel.ERROR,'Error while trying to update HCP DT Call Accrual. ' +ex.getStackTraceString());
}
}
DEBUG LOG POINTS BELOW ERROR:
03:37:15.327 (15327129889)|SYSTEM_METHOD_ENTRY|[93]|Database.update(LIST) 03:37:15.327 (15327159952)|DML_BEGIN|[93]|Op:Update|Type:HCP_Depth_Tracker_OAPI__c|Rows:1 03:37:15.362 (15362307989)|DML_END|[93] 03:37:15.362 (15362410665)|SYSTEM_METHOD_EXIT|[93]|Database.update(LIST) 03:37:15.362 (15362473119)|SYSTEM_CONSTRUCTOR_ENTRY|[96]|(Integer) 03:37:15.362 (15362484879)|SYSTEM_CONSTRUCTOR_EXIT|[96]|(Integer) 03:37:15.362 (15362500436)|SYSTEM_METHOD_ENTRY|[97]|LIST.iterator() 03:37:15.362 (15362515576)|SYSTEM_METHOD_EXIT|[97]|LIST.iterator() 03:37:15.362 (15362528617)|SYSTEM_METHOD_ENTRY|[97]|system.ListIterator.hasNext() 03:37:15.362 (15362549320)|SYSTEM_METHOD_EXIT|[97]|system.ListIterator.hasNext() 03:37:15.362 (15362611297)|SYSTEM_METHOD_ENTRY|[97]|system.ListIterator.hasNext() 03:37:15.362 (15362624387)|SYSTEM_METHOD_EXIT|[97]|system.ListIterator.hasNext() 03:37:15.362 (15362668347)|SYSTEM_METHOD_ENTRY|[102]|String.valueOf(Object) 03:37:15.362 (15362693710)|SYSTEM_METHOD_EXIT|[102]|String.valueOf(Object) 03:37:15.362 (15362721807)|SYSTEM_METHOD_ENTRY|[102]|System.debug(ANY) 03:37:15.362 (15362732118)|USER_DEBUG|[102]|DEBUG|Failed HCP Call Accrual rows {}
Please let me know if someone can help here.