function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jim FisherJim Fisher 

Batch class not executing - Getting a fatal error

I'm hoping you can help please.

We are executing a Batch class from Scheduler Class - it is not executing. We tried to run Batch class from Execute anonymous, still not working and throws an error "Internal Salesforce Error" (attached error below)

Very much appreciate any ideas.

Thanks
Jim
jim.fisher@spandex.com.au

Batch Class fatal error
UC InnovationUC Innovation
Hi Jim,

Unfortunately these are the most difficult to debug in my honest oppinion. The error message 'Internal Salesforce Error' doesnt really give even a hint on where to look for a solution. I will be more than happy to help but i will need a bit more info.

What is your batch query doing?
What is your execute doing?

Things like this can shed a bit of light on the matter and can give you a starting point. In the past when I hit this error it was due to, for examply, me doing a sub query in the batch query. Another thing you might want to consider is making your batch query more selective since it might be the cause. These two are a good plece to start.

Try turning on debug logs to help figure out where it is failing.

Hope this helps!

AM
Jim FisherJim Fisher
Thanks AM for your fast response.

The query is identifying tasks in the Account Activity History where the subject contains %Email%, then identifying (ActivityFlag) if the 'Date Due' is greater than 14 from (Today) based on various SELECT's.  We originally had a tome out, so reducted the select down to examining around 2,500 accounts (looking at WorkBench).

Here's the script if this will help:

Thanks Jim

/*********************************************
Class name : EmailActivityBatchClass
Description : This is a batch class for populating the Email Activity Flag on Accounts based on the email sent date.       
*********************************************/
global class EmailActivityBatchClass implements Database.Batchable<sObject> {
   
    global List<Task> taskList = new List<Task>();
    global Set<Id> setOfAccountId = new Set<Id>();
    global List<Account> acctList = new List<Account>();
 //global List<task> taskList = new List<Task>();
   
   
 global EmailActivityBatchClass(){
 
  date crdDate = system.today() - 14 ;
  taskList = [SELECT id, Subject, Type, ActivityDate, AccountId,CreatedDate FROM task WHERE AccountId !=null AND Subject Like '%Email%' AND Status = 'Completed' AND Type = 'Email' AND ActivityDate <= : crdDate LIMIT 50000];
 
  if(!taskList.isEmpty()){
            for(Task tsk : taskList){
                setOfAccountId.add(tsk.AccountId);
            }
        }
 
 
 }
 
    global Database.QueryLocator start(Database.BatchableContext bc) {
 
 
        String query = 'SELECT id, ActivityFlag__c,Name,KP1_YTD_Sales__c,KP2_YTD_Sales__c,Sales_YTD__c,Sales_YTD_LY__c FROM Account WHERE Id IN : setOfAccountId AND ActivityFlag__c = false AND KP1_YTD_Sales__c > 20 AND KP2_YTD_Sales__c > 20 AND Sales_YTD__c > 100 AND Sales_YTD_LY__c > 100 AND Sales_Organization__c = \'6800-AU\'';
       
        return Database.getQueryLocator(query);
    }// End of Start method
   
    global void execute(Database.BatchableContext BC, List<Account> scope) {
       
        List<Account> updateAccountList = new List<Account>();
       
       
        if(!scope.isEmpty()){
            for(Account acc : scope){
              
                   acc.ActivityFlag__c = true;
                   updateAccountList.add(acc);
   }
           
            system.debug('***updateAccountList*'+updateAccountList);
        }
       
       
        if(!updateAccountList.isEmpty()){
            database.update(updateAccountList,false);
        }
       
    }// End of execute method
   
    global void finish(Database.BatchableContext BC){
            // Logic to be Executed at finish
           
         /*   AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
               TotalJobItems, CreatedBy.Email
               FROM AsyncApexJob WHERE Id =
               :BC.getJobId()];
            // Send an email to the Apex job's submitter notifying of job completion.
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {a.CreatedBy.Email};
            mail.setToAddresses(toAddresses);
            mail.setSubject('Apex Sharing Recalculation ' + a.Status);
            mail.setPlainTextBody('The batch Apex job processed ' + a.TotalJobItems +
             ' batches with '+ a.NumberOfErrors + ' failures.');
             system.debug('&'+a.TotalJobItems +' batches with '+ a.NumberOfErrors);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
          */
    }// End of Finish method
}