• Tanvi Sharma
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

Hi folks,

 

I'm trying to create a scheduled outbound email. The class queries for all of the custom objects whose date fields are today and emails people whose email addresses are recorded as custom fields within the object. Only... it doesn't work. The code, and its schedule class, below do absolutely nothing.

 

public class EmailMessage
{  
   public static void SendEmail()
   {
       List<Milestone1_Project__c> activeproc = new List<Milestone1_Project__c>([Select id from
                                                                                 Milestone1_Project__c]);
       
       for( integer i=0;i<activeproc.size();i++){
       if(System.Today()==date.newinstance(activeproc[i].Date__c.year(),activeproc[i].Bid_Review__c.month(),activeproc[i].Date__c.day())){
       
       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       String[] address = new String[]{activeproc[i].Owner.Email,activeproc[i].Legal_Contributor__c,activeproc[i].Technical_Specialist__c};
        mail.setToAddresses(address);
       
       for(OrgWideEmailAddress owa : [select id, Address from OrgWideEmailAddress]){
			mail.setOrgWideEmailAddressId(owa.id);
       }
 		
 
       mail.setSubject('Record of hours spent on Procurement: ' +activeproc[i].Name);
       mail.setBccSender(false);
       mail.setUseSignature(false);
       mail.setPlainTextBody('This is a test.');
       List<Messaging.SendEmailResult> results = Messaging.sendEmail(new Messaging.Email[] { mail });
       System.debug('Email Sent: '+results.get(0).isSuccess() );
    }
   }
}
}

 And the Scheduler class:

 

global class ScheduleEnable implements Schedulable{
    global void execute (SchedulableContext SC){
        EmailMessage e = new EmailMessage();
    }
}

 Which I've then selected to run every week day at 08:00.

 

Does anyone see why this might not be working? I can't figure it out at all. It looks fairly solid to me, but I'm not certain about the String array. Am I barking up the right tree?

 

Any help you lovely folk of the Developer Force community could give would be much appreciated.

 

Thanks,

Lee