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
Ap30Ap30 

Count of records processed in batch class

Hi All,
In my below code i have to get the count of 'unchecked' records whenever apex is executed in batch class. Please guide me how to get the count for only 'unchecked' records found.

if(t.Profile__c == null)
            {
        t.Status__c = 'Fill data';
            }
            else if(t.Profile__c != null && t.Check__c == 'No')
            {
                t.Verification_Status__c = 'Unchecked';
              
            }
Best Answer chosen by Ap30
Suraj Tripathi 47Suraj Tripathi 47
Hi Ap30,

If you want to get the count of 'unchecked' records. You can take the reference from this below code. Maybe this code will help you. 
integer count=0;
if(t.Verification_Status__c !=true){
    count++;
 }
In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

 

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi Ap30,

If you want to get the count of 'unchecked' records. You can take the reference from this below code. Maybe this code will help you. 
integer count=0;
if(t.Verification_Status__c !=true){
    count++;
 }
In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

 
This was selected as the best answer
CharuDuttCharuDutt
Hii Ap30
Try Below Code
integer count = 0;
For(Account Acc : [Select id,type from Account]){
    if(Acc.type == null){ 
        count++;    
        System.debug('Count==> '+count );
  }
}
Please Mark It As Best Answer If It Helps
Thank You!
AbhinavAbhinav (Salesforce Developers) 
Hi AP30,

To maintain count of records processed across transaction in batch Apex you have to use stateful batch apex i.e implements Database.Stateful.Please find below reference

When to use stateful:
https://salesforce.stackexchange.com/questions/175355/database-stateful-when-to-use-it/175371

Sample code with counter
https://salesforce.stackexchange.com/questions/123880/put-a-counter-in-batch-apex-class

Please mark this answer as best if it helps so that others facing same issue will find it useful.

Thanks!