You need to sign in to do that
Don't have an account?
Rakesh Samal
I want to send email to CEO when how many trainers is found unverified in batch class finish method
Custom object: Trainer_Master__c
picklist Field: Verification_status__c(details needed, verified, unverified)
how many trainers are found unverified? Then Send email to CEO in batch apex finish method. This all work should be on finish method batch class.
Please help me on this
picklist Field: Verification_status__c(details needed, verified, unverified)
how many trainers are found unverified? Then Send email to CEO in batch apex finish method. This all work should be on finish method batch class.
Please help me on this
Do you want to send email on daily basis?
Thanks!!
No. on Friday 6 PM only which I have done using CRON Expression.
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
Can I write this code on finish method? Because we have to write code in finish method
global class TrainerMasterClass implements Database.Batchable<sObject>,Database.Stateful {
global Database.QueryLocator start(Database.BatchableContext BC)
{
// string vfstatus = 'Non Verified';
string query = 'SELECT LinkedIn_Profile__c,Background_Check_Done__c,Verification_Status__c FROM Trainer_Master__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, list<Trainer_Master__c> scope)
{
for(Trainer_Master__c varTrainerMaster:scope)
{
if(varTrainerMaster.LinkedIn_Profile__c==null)
{
varTrainerMaster.Verification_Status__c = 'Details Needed';
}
else if(varTrainerMaster.LinkedIn_Profile__c!=null && varTrainerMaster.Background_Check_Done__c=='No')
{
varTrainerMaster.Verification_Status__c = 'Non Verified';
}
else if(varTrainerMaster.LinkedIn_Profile__c!=null && varTrainerMaster.Background_Check_Done__c=='Yes')
{
varTrainerMaster.Verification_Status__c = 'Verified';
}
}
update scope;
}
global void finish(Database.BatchableContext BC)
{
// list<Trainer_Master__c> scope = New list<Trainer_Master__c>();
// set<id> countofids = new set<id>();
// for(Trainer_Master__c con:scope){
// countofids.add(con.id);
// }
// if(countofids.size()>0){
// Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// String[] toAddresses = new String[] {'rakeshsamal0323@gmail.com'};
// mail.setToAddresses(toAddresses);
// mail.setSubject('count of unvarified trainers');
// mail.setPlainTextBody('Total unvarified trainers count is ' +' '+ countofids.size());
// Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
// }
}
}
Thanks for ur answer. I modified my code in finish method and it is working correctly.