Skip to main content
fixed code formatting
Source Link
Derek F
  • 64.1k
  • 15
  • 55
  • 104

I have batch apex which updates Lead owner name,processing 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,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 scope) { List leads = (List) 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);

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.

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,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 scope) { List leads = (List) 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.

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.

Source Link

batch apex terminated unexpectedly

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,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 scope) { List leads = (List) 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.