global class ReminderBatch implements Database.Batchable<SObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
// Query for clients with active Crossroads Community User Login profiles who have not created an appointment in the current month
String query = 'SELECT Id, Name, Email, HouseholdPreferredLanguage__c, Account.Last_Visit_Date__c FROM Contact WHERE Id IN (SELECT ContactId FROM User WHERE Profile.Name = "Crossroads Community Login User")';
system.debug('query' + query);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Contact> cont) {
List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
// Sending email to client in the client's preferred language
for (Contact c : cont) {
system.debug('-contact-' + c);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
if (c.HouseholdPreferredLanguage__c == 'Spanish') {
email.setTemplateId('00X56000003FlkJ');
//email.setSubject('Despensa de Crossroads: Recordatorio para hacer su pedido');
} else {
email.setTemplateId('00X56000003FlkE');
//email.setSubject('Crossroads Pantry: Reminder to Place your Order');
}
email.setToAddresses(new List<String>{ c.Email });
email.setTargetObjectId(c.Id);
email.setSaveAsActivity(true);
emailList.add(email);
}
Messaging.sendEmail(emailList);
system.debug('Batch class is executed successfully');
}
global void finish(Database.BatchableContext BC) {
system.debug('Batch class is executed successfully');
}
}
Can anyone please guide me regarding the above batch apex class, when I am trying to execute the batch apex class, here I am not getting the required records in the developer console log from start method but the same SOQL query is working in salesforce inspector as well as in query editor as well.
#Salesforce Developer #Official Salesforce Success Community Groups