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;


        for(Account a : accounts){

            for(AccountTeamMember atm : a.AccountTeamMembers){

                Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                email.setSenderDisplayName('Salesforce Team');
                String[] ccList = new List<String>();


                System.debug('***********************'+ msgList);

    if(msgList.size() > 0){



  • 2
    Make sure that you have the email access level set to All Email. The setting is found in Setup | Email Administration | Deliveribility. The setting defaults to No Access when a sandbox is created. Also make sure that the users email addresses are correct as they get changed as well when the sandbox is created
    – BarCotter
    Commented Feb 3, 2015 at 18:13
  • Email settings are configured correctly and double checked before posting. Thank you
    – humanoid
    Commented Feb 3, 2015 at 18:19
  • 2
    I see you have a debug statement to output the msgList. Are there messages in the list in the debug statement? Commented Feb 3, 2015 at 18:23
  • Shouldn't your SOQL query on account also include AccountTeamMembers?
    – BarCotter
    Commented Feb 3, 2015 at 18:32

1 Answer 1


You are not querying AccountTeamMembers when you are querying the Account records. The loop below is never executed because of this

for(AccountTeamMember atm : a.AccountTeamMembers){

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .