You need to sign in to do that
Don't have an account?
Pradeep d
how to count total number of records in batch apex
wanted to count total number of records
public List<Contact> contactsize = new List<Contact>(); global void execute(Database.BatchableContext bc, List<Contact> Scope){ conupdate = new List<Contact>(); system.debug('calling update check execute'); For(Contact c: Scope){ c.Direct_send__c= true; conupdate.add(c); } system.debug('contact list' + conupdate.size()); contactsize.addAll(conupdate); update conupdate; } global void finish(Database.BatchableContext bc){ system.debug('contacts size :' + contactsize.size()); recordcount = contactsize.size();
To avoid error check once below link :
https://help.salesforce.com/articleView?id=000239885&type=1
Thanks
Varaprasad
All Answers
Initialize an Integer count=0;
as
For(Contact c: Scope){
c.Direct_send__c= true;
conupdate.add(c);
count++;
}
count will retain its value between transactions.
@Abdul Ayan
Database.stateful @ Heap memory issues are getting
Am getting this error with stateful
First error: Batchable instance is too big: updatecheck
Please check once below sample code :
Hope this helps you
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
To avoid error check once below link :
https://help.salesforce.com/articleView?id=000239885&type=1
Thanks
Varaprasad