• Tom-Barber
  • NEWBIE
  • 15 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I am 12-years into Salesforce BUT new to APEX coding and am writing a class to simply trigger an update on all records on Budget__c in order to fire some declarative workflow rules (if anyone has ideas on how to improve the class, please suggest).

The main probem is I am getting an Execute Anonymous Error Line 1 Column 1 Invalid Type: batchBudgetMonthlyUpdate. But this did work and not it doesn't. I don't think I changed anything but maybe I did. The only thing I can think of is I tested it, it worked, then I logged out of sandbox and into production. When I logged back into sandbox, is when it stopped working. I tried checking environment but cannot figure out if this is related or not.
 
// Batch Job for updating all Budget records on the 1st of each month
// 23 April 2020 by Tom Barber cloudconsulting, LLC
global class BudgetMonthlyUpdate implements Database.Batchable<sObject> {
    global String [] email = new String[] {'tbarber@cloudconsultingllc.com'};
   // Email address is used below to send batch job status messages
   
   // Start Method
   global Database.Querylocator start (Database.BatchableContext BC) {
      return Database.getQueryLocator('SELECT id FROM Budget__c');
      // Query to get all the Budget__c object record IDs from all the Budget__c records--no WHERE statement
   }
   
   // Execute method
   global void execute (Database.BatchableContext BC, List<Budget__c> scope) {
       for(Budget__c a : scope)
       {a.Id = a.Id;
       }
     
      if (scope != null && scope.size()>0) {
         // Check if List is empty or not
         Database.update(scope); System.debug('List Size'
            + scope.size());
         // Update the Budget records-doesn't change the value of any record. Basically is a trigger to update all
      }
}
 
   // Finish Method
   global void finish(Database.BatchableContext BC) {
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      
      // The code below will fetch the job Id
      AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors,
      a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById,
      a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];//get the job Id
      System.debug('$$$ Jobid is '+BC.getJobId());
       String APEXjobID = null;
       APEXjobID = +BC.getJobId();
          
      // the code below will send an email to User about the job status
      mail.setToAddresses(email);
      mail.setReplyTo('tbarber@cloudconsultingllc.com'); //Add your email address here
      mail.setSenderDisplayName('RLG Salesforce Apex Batch Processing');
      mail.setSubject('Monthly Budget Update Batch Processing: '+a.Status);
      mail.setPlainTextBody('Apex job ' + APEXjobID +' | Monthly Budget Update completed' + a.CompletedDate + 'with status: ' + a.ExtendedStatus
                            + '\n' + 'This job runs on the 1st of each month and updates all the Budget records on the object so the current month (and year) checkboxes are checked.'
                            + '\n' + a.TotalJobItems+ ' batches with '+a.NumberOfErrors+' failures.'
                            + '\n' + 'Job Items processed:' +a.JobItemsProcessed);
      Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
   }
}
Thanks in advance for any help or advice.
 
I am 12-years into Salesforce BUT new to APEX coding and am writing a class to simply trigger an update on all records on Budget__c in order to fire some declarative workflow rules (if anyone has ideas on how to improve the class, please suggest).

The main probem is I am getting an Execute Anonymous Error Line 1 Column 1 Invalid Type: batchBudgetMonthlyUpdate. But this did work and not it doesn't. I don't think I changed anything but maybe I did. The only thing I can think of is I tested it, it worked, then I logged out of sandbox and into production. When I logged back into sandbox, is when it stopped working. I tried checking environment but cannot figure out if this is related or not.
 
// Batch Job for updating all Budget records on the 1st of each month
// 23 April 2020 by Tom Barber cloudconsulting, LLC
global class BudgetMonthlyUpdate implements Database.Batchable<sObject> {
    global String [] email = new String[] {'tbarber@cloudconsultingllc.com'};
   // Email address is used below to send batch job status messages
   
   // Start Method
   global Database.Querylocator start (Database.BatchableContext BC) {
      return Database.getQueryLocator('SELECT id FROM Budget__c');
      // Query to get all the Budget__c object record IDs from all the Budget__c records--no WHERE statement
   }
   
   // Execute method
   global void execute (Database.BatchableContext BC, List<Budget__c> scope) {
       for(Budget__c a : scope)
       {a.Id = a.Id;
       }
     
      if (scope != null && scope.size()>0) {
         // Check if List is empty or not
         Database.update(scope); System.debug('List Size'
            + scope.size());
         // Update the Budget records-doesn't change the value of any record. Basically is a trigger to update all
      }
}
 
   // Finish Method
   global void finish(Database.BatchableContext BC) {
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      
      // The code below will fetch the job Id
      AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors,
      a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById,
      a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];//get the job Id
      System.debug('$$$ Jobid is '+BC.getJobId());
       String APEXjobID = null;
       APEXjobID = +BC.getJobId();
          
      // the code below will send an email to User about the job status
      mail.setToAddresses(email);
      mail.setReplyTo('tbarber@cloudconsultingllc.com'); //Add your email address here
      mail.setSenderDisplayName('RLG Salesforce Apex Batch Processing');
      mail.setSubject('Monthly Budget Update Batch Processing: '+a.Status);
      mail.setPlainTextBody('Apex job ' + APEXjobID +' | Monthly Budget Update completed' + a.CompletedDate + 'with status: ' + a.ExtendedStatus
                            + '\n' + 'This job runs on the 1st of each month and updates all the Budget records on the object so the current month (and year) checkboxes are checked.'
                            + '\n' + a.TotalJobItems+ ' batches with '+a.NumberOfErrors+' failures.'
                            + '\n' + 'Job Items processed:' +a.JobItemsProcessed);
      Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
   }
}
Thanks in advance for any help or advice.