You need to sign in to do that
Don't have an account?
Akshat Tiwari 2
I am trying to maintain states accross the transaction and I am getting error " Variable Does Not Exist: recordsProcessed " when I am tring to store values inside the recordsProcessed inside for loop. What modifications should I make in the code?
Need Help With The DataBase.Stateful
global class TeacherBonusClass implements database.Batchable<sObject>, Database.Stateful{ global Integer recordsProcessed = 0; global static Database.QueryLocator start(Database.BatchableContext bc){ return Database.getQueryLocator('Select Name, Salary__c from Teacher__c'); } global static void execute(Database.BatchableContext bc, List<Teacher__c> teaList){ List<Teacher__c> teaNewList = new List<Teacher__c>(); for(Teacher__c tea: teaList){ if(tea.Salary__c< 300000){ tea.Salary__c = tea.Salary__c + (0.002 * tea.Salary__c); teaNewList.add(tea); } recordsProcessed = recordsProcessed + 1; } insert teaNewList; } global static void finish(Database.BatchableContext bc){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); string[] toAddresses = new String[] {'akshattiwari489@gmail.com'}; mail.setSubject('Salary Bonus Alert'); mail.setToAddresses(toAddresses); mail.setPlainTextBody('Your Salary Has been Incremented by 0.2% and your new salary is'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } }
I am trying to maintain states accross the transaction and I am getting error " Variable Does Not Exist: recordsProcessed " when I am tring to store values inside the recordsProcessed inside for loop. What modifications should I make in the code?
try this class:
Please check line "insert teaNewlist" as you are missing mandatory fields in mapping.
Thanks
Anil.B
Your code is correct , should not through error,
you can try Instead of
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Here is modified code
The error it shows is Variable does not exist: recordsProcessed What could be the possible reason for error?