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
Tom-BarberTom-Barber 

My class executed before. But now it doesn't. Execute Anonymous Error Invalid Type Line 1 Column 1

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.
 
Best Answer chosen by Tom-Barber
SarvaniSarvani
Hi Tom,

I believe your batch class name is BudgetMonthlyUpdate. How are you trying to execute the batch class ?
If you are trying to execute your batch class through Developer console->Execute Anonymus window the above error you mentioned may occur as your using incorrect calss name batchBudgetMonthlyUpdate.
Try executing your batch class with below code
1. Go to Setup --> Open Developer Console.
2. Select Debug tab --> Open Execute Anonymous Window
3.  In the opened window, paste below line
Database.executeBatch(new BudgetMonthlyUpdate());
You can also mention batch size, number of records to be processed using below syntax
Database.executeBatch(new BudgetMonthlyUpdate(), 200);

Hope this helps! Please mark as best if it solves your issue

Thanks

All Answers

SarvaniSarvani
Hi Tom,

I believe your batch class name is BudgetMonthlyUpdate. How are you trying to execute the batch class ?
If you are trying to execute your batch class through Developer console->Execute Anonymus window the above error you mentioned may occur as your using incorrect calss name batchBudgetMonthlyUpdate.
Try executing your batch class with below code
1. Go to Setup --> Open Developer Console.
2. Select Debug tab --> Open Execute Anonymous Window
3.  In the opened window, paste below line
Database.executeBatch(new BudgetMonthlyUpdate());
You can also mention batch size, number of records to be processed using below syntax
Database.executeBatch(new BudgetMonthlyUpdate(), 200);

Hope this helps! Please mark as best if it solves your issue

Thanks
This was selected as the best answer
Tom-BarberTom-Barber
Score! That did it! I don't know what I did to make it work 1 time but somehow messed up the code in the Execute Anonymous window when I went back and did it the subsequent times (maybe I typed it in again and it was already there but I didn't scroll over???? not sure).

Anyway, I also need help with the test class for this. I wrote one to insert records. It wored but it had 0% coverage. Thinking I have to write one that updates records but getting stuck on what the class should have.
  • Will insert provide coverage? or do I have to write an update test (if so, what this class does is so simple, can't I just repeat what's in it for the test?)
  • What would the assert statement look like?
  • Does the test class have to test the finish statments that send out the single email?
Any suggestions would be appreciated. And, again thanks for the help in getting me going with APEX code.
SarvaniSarvani
Hi Tom,

Apologize for delayed response. Since your batch class is just to invoke trigger with psuedo update, just try to insert new account and call the batch class in test class. Try using below code which give 100% coverage:
@isTest public class BudgetmonthlyUpdatetestclass {

 @isTest  public static void Class_Test_Method()
    {
        List<Budget__c> Budgetlist = New List<Budget__c>();
        Budget__c budget1 = new Budget__c();
        budget1.name='Test Budget';
       // Add other required fields to insert Budget record successfully
        Budgetlist.add(budget1);
        Test.startTest();
        Database.SaveResult []str = Database.insert(Budgetlist ,false);
        system.assertEquals(True, str[0].isSuccess());
        BudgetMonthlyUpdate batchclass= New BudgetMonthlyUpdate();
        Database.executeBatch(batchclass);
        Test.stopTest();
    }
}
Hope this helps!

Thanks
Tom-BarberTom-Barber
Thanks so much for the reply. All done! sarvani thota replied to your question at 12:15 PM on 4/27/2020. Original question: 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 { 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 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. Reply: Hi Tom, Apologize for delayed response. Since your batch class is just to invoke trigger with psuedo update, just try to insert new account and call the batch class in test class. Try using below code which give 100% coverage: @isTest public class BudgetmonthlyUpdatetestclass { @isTest public static void Class_Test_Method() { List Budgetlist = New List(); Budget__c budget1 = new Budget__c(); budget1.name='Test Budget'; // Add other required fields to insert Budget record successfully Budgetlist.add(budget1); Test.startTest(); Database.SaveResult []str = Database.insert(Budgetlist ,false); system.assertEquals(True, str[0].isSuccess()); BudgetMonthlyUpdate batchclass= New BudgetMonthlyUpdate(); Database.executeBatch(batchclass); Test.stopTest(); } } Hope this helps! Thanks Tip! To respond, either reply to this email or click this link: https://developer.salesforce.com/forums/ForumsMain?id=9062I000000Xwyh