+ Start a Discussion

Specify Recipient Email Address in Mass Email



I installed the Birthday Reminder app from the Appexchange store. The code is unmanaged and I was trying to change the field from which the code is pulling the email address from for the recipient. I tried a couple of different ways, but none of them worked. Please help. Here is the code:


global class BirthdayCronJob implements Schedulable{ 
		global void execute(SchedulableContext SC) {
		public List<Id> getBirthdayEmailAddresses(Integer Month, Integer Day) 
        	List<Id> mailToIds = new List<Id>();
	        Contact[] c = [SELECT Id, email, Birthdate, Send_Birthday_Email__c, HasOptedOutOfEmail
	        				FROM Contact 
	        				WHERE DAY_IN_MONTH(Birthdate) = : Day 
						AND CALENDAR_MONTH(Birthdate) = : Month   
    	    for(Contact recipient : c) {
    	    		if (recipient.Send_Birthday_Email__c == true && recipient.HasOptedOutOfEmail == false)
    	    			System.Debug('\n*******Recipient: '+ recipient.email);
    	    		} else {
    	    			System.Debug('\n*******NO Recipient');
        	return mailToIds;
        public void sendMail() 
		String debugAddress = 'eyewell@salesforce.com';
		String BirthdayEmailTemplateName = 'Happy_Birthday';
		String AnniversaryEmailTemplateName = 'Celebrating_your_Anniversary';			
		String debugMessage;
        	String[] toAddresses;

    		Integer DayOfEvent   = date.today().day();
			Integer MonthOfEvent = date.today().month();
        	List<Id> BirthdayIdsList = getBirthdayEmailAddresses(MonthOfEvent,DayOfEvent);

        	EmailTemplate birthdayTemplate = [select Id,Name,Subject,body from EmailTemplate where DeveloperName = :BirthdayEmailTemplateName];
        	if(birthdayTemplate != null && BirthdayIdsList.isEmpty() == false)

           		Messaging.MassEmailMessage birthdayMail = new Messaging.MassEmailMessage();

            	try {
            		Messaging.sendEmail(new Messaging.MassEmailMessage[] { birthdayMail });
            	}catch(Exception e)
            	        System.Debug('BirthdayCronJob:sendMail(): Either an email template could not be found, or no Contact has a birthday today');


 So instead of the native Force.com Email field, I want to use a custom email field called "Secondary Email." I tried changing the SOQL statement, but it still didnt work.