You need to sign in to do that
Don't have an account?
Sanjay Vinayak T
How to count the Number of records updated from Batch class?
Hi All,
I have created a batch class to update the fields.
i want the count of the field updated based on the condition.
Above is my Batch class code and I want to count the number of records with the Verification_Status__c = 'Non Verified'.
Kindly help me in enhancing the code.
Thanks in advance.
Regards,
Sanjay Vinayak T
I have created a batch class to update the fields.
i want the count of the field updated based on the condition.
Global class BatchUpdateTrainer implements Database.Batchable<Sobject> { Global database.QueryLocator start(database.BatchableContext BC){ return Database.getQueryLocator('Select id, Background_Check_Done__c, LinkedIn_Profile__c, Verification_Status__c from Trainer_Master__c); } Global void execute(database.BatchableContext BC, List<Trainer_Master__c> Scope){ list<Trainer_Master__c> lstTM = new list<Trainer_Master__c>(); for (Trainer_Master__c trainer : Scope){ system.debug('Background Check Done >>>> ' + trainer.Background_Check_Done__c); system.debug('LinkedIn Profile >>>> ' + trainer.LinkedIn_Profile__c); if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c == null){ trainer.Verification_Status__c = 'Details Needed'; system.debug('Verification_Status__c1 ' + trainer.Verification_Status__c); } else if(trainer.Background_Check_Done__c =='No' && trainer.LinkedIn_Profile__c!= null){ trainer.Verification_Status__c = 'Non Verified'; system.debug('Verification_Status__c2 ' + trainer.Verification_Status__c); } else if(trainer.Background_Check_Done__c =='Yes' && trainer.LinkedIn_Profile__c!= null){ trainer.Verification_Status__c = 'Verified'; system.debug('Verification_Status__c3 ' + trainer.Verification_Status__c); } lstTM.add(trainer); } if(!lstTM.IsEmpty()){ update lstTM; } } Global void finish(database.BatchableContext BC){ } } TO Execute BatchUpdateTrainer M = new BatchUpdateTrainer (); Database.executeBatch(M);
Above is my Batch class code and I want to count the number of records with the Verification_Status__c = 'Non Verified'.
Kindly help me in enhancing the code.
Thanks in advance.
Regards,
Sanjay Vinayak T
Refer to this answer https://developer.salesforce.com/forums/?id=906F0000000kGqFIAU#:~:text=Please%20find%20the%20below%20code,count%20%3D%200%3B%20public%20Database.
Thanks,
Amol, www.cloudwaale.com
All Answers
Refer to this answer https://developer.salesforce.com/forums/?id=906F0000000kGqFIAU#:~:text=Please%20find%20the%20below%20code,count%20%3D%200%3B%20public%20Database.
Thanks,
Amol, www.cloudwaale.com
Thanks for sharing the reference answer, problem got solved.
will you be able to help with the below-mentioned problem?
I wanted to show a custom error message on the Visualforce page for the below code.
Kindly help me in fixing the code and show the error message.
Regards,
Sanjay.