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.

  • 4
    I could not see any DML statement in your execute or finish method if its your complete code – Raul Jan 25 '17 at 15:13
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.