0

I have batch apex which updates Lead owner name, processing a huge number of records. Batch apex stops processing batches after some number of records are processed and finishes unexpectedly and shows Apex Job status = Completed. No error is reported, no exception is thrown. I check debug logs to see the value in count variable is less than what is expected. Here is what I am trying to do.

Public class MassUpdateOwner implements Database.Batchable<SObject>,Database.Stateful
{
   private Integer callCount = 0; 
   Public ID targetUserId; //used to capture new User ID
   Public MassUpdateOwner (String ownerUsername)   
   {
        User u = [select Id from User where Username = new user name limit 1];
        TargetUserId = u.Id;
   }
   Public Database.QueryLocator START(Database.BatchableContext ctx)
   {
        Return Database.getQueryLocator([select OwnerId from Lead]);
    }
   Public void EXECUTE(Database.BatchableContext ctx, List<Lead> scope) 
   {
       List<Lead> leads = (List<Lead>) scope;
       For (Lead l: leads) 
       {
         l.OwnerId = targetUserId; 
      }
      callcount++;
    }
   Public void finish (Database.BatchableContext ctx) 
   {
        // Send an email or something
   }

Id batch Job Id = Database.executeBatch(new MassUpdateOwner(), 1); 
}

My question is should I run the batch apex again? Pls let me know.

1
  • 4
    I could not see any DML statement in your execute or finish method if its your complete code
    – Raul
    Commented Jan 25, 2017 at 15:13

1 Answer 1

1

This may be the known issue in Spring '17: Batch Apex job finishes unexpectedly in Spring'17 without processing all specified records, which is currently in process of being released.

2
  • 1
    Let me know if your org is not on Spring '17 though - there's another issue that I'm investigating where a long-running batch process is hitting a CPU timeout and not being reported as a failure that may be a separate issue: salesforce.stackexchange.com/questions/156902/… Commented Jan 25, 2017 at 17:47
  • My orgz is not using spring 17 Commented Jan 26, 2017 at 4:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .