From the Apex Scheduler

Finally, let's look at an example from the SeasonNewsletterScheduler class. As with the controller example, it handles the exceptions itself, in this case, by emailing the user with any failures. Consider the following code:

global void execute(SchedulableContextsc) { 
  try { 
    SeasonService.issueNewsLetterCurrentSeason(); 
  } catch (Exception e) { 
    Messaging.SingleEmailMessage mail = 
new Messaging.SingleEmailMessage(); mail.setTargetObjectId(UserInfo.getUserId()); mail.setSenderDisplayName(UserInfo.getUserName()); mail.setSubject('Failed to send Season Newsletter'); mail.setHtmlBody(e.getMessage()); mail.setSaveAsActivity(false); Messaging.sendEmail(
new Messaging.SingleEmailMessage[] { mail }); } }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.196.103