0

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.

7
  • Your problem may be that the HcpCallMap does not contain the dt.HCP_Account_OAPI__c. Also, does your system.debug(scRows ); output any information? You should debug the r.getErrors() as well to see what the cause is.
    – Eric
    Sep 25, 2014 at 6:28
  • Hi Eric! I can not see debug log for this. I set my User in debug log,since it is in production lots of jobs running at that time and debug logs are lost.Can you suggest me a way out? Sep 25, 2014 at 7:11
  • Unless it is very long, I think you should post the entire class in your question because e.g. how HcpCallMap is populated and its lifecycle are important.
    – Keith C
    Sep 25, 2014 at 8:16
  • As a possible workaround (although this may not be possible as it is in production) try to create a debug object that you save the r.getErrors() to. You can then later delete this object. Without that it is extremely hard to help.
    – pbattisson
    Sep 25, 2014 at 8:47
  • Another suggestion on the debugging is to schedule this batchable using a different user than the other batchables so that it has its own log file.
    – Keith C
    Sep 25, 2014 at 8:53

0

You must log in to answer this question.

Browse other questions tagged .