I want to send out alert emails to account team members when their account(s) contracts are up for renewal 120 days from 'today'. I have test accounts created to meet the soql criteria, I'm in the account team in all of em but I'm getting no emails. Below is my apex code. Any help will be appreciated :)
public with sharing class AccountRenewalReminder{
Account[] accounts;
List<Messaging.SingleEmailMessage> msgList;
public AccountRenewalReminder(){
msgList = new List<Messaging.SingleEmailMessage>();
accounts = new List<Account>([SELECT Name, OwnerId, Account_Id__c, Carrier_Id__c, Contract_Renewal_Date__c, Type FROM Account WHERE X120_Day_Renewal_Reminder__c = TODAY AND Termination_Date__c = NULL AND Contract_Executed_on_Client__c = 'Yes' LIMIT 50000]);
Id emailTemplateId = [SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Account_90_Contract_Renewal'].Id;
if(!accounts.isEmpty()){
for(Account a : accounts){
for(AccountTeamMember atm : a.AccountTeamMembers){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTemplateId(emailTemplateId);
email.setTargetObjectId(atm.UserId);
email.setBccSender(false);
email.setUseSignature(false);
email.setSenderDisplayName('Salesforce Team');
email.setSaveAsActivity(false);
String[] ccList = new List<String>();
ccList.add(System.Label.UserEmailId);
//email.setCcAddresses(ccList);
msgList.add(email);
System.debug('***********************'+ msgList);
}
}
}
if(msgList.size() > 0){
Messaging.sendEmail(msgList);
}
}
}
AccountTeamMembers
?