You need to sign in to do that
Don't have an account?
Tom-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.
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 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 You can also mention batch size, number of records to be processed using below syntax
Hope this helps! Please mark as best if it solves your issue
Thanks
All Answers
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 You can also mention batch size, number of records to be processed using below syntax
Hope this helps! Please mark as best if it solves your issue
Thanks
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.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: Hope this helps!
Thanks