使用触发器使用模板发送电子邮件

时间:2013-06-11 15:18:29

标签: apex-code visualforce

我有以下触发器:

trigger send_notification on Inquery__c (after update) {

  Inquery__c inquery = trigger.new[0]; 
  String[] toAddresses = new String[] {inquery.email__c}; 
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

  mail.setTargetObjectId(inquery.OwnerID);
  mail.setSenderDisplayName('Salesforce Support');
  mail.setUseSignature(false);
  mail.setBccSender(false);
  mail.setSaveAsActivity(false);

 if (Trigger.isUpdate) { 
    if(inquery.Quilification__c == 'Qualified') {
          EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'Invitation_to_register_for_Class'];
          mail.setTemplateId(et.id);
          Messaging.SendEmailResult [] r = 
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});   
      } 
    if(inquery.Quilification__c == 'Disqualified') {
          EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'Ineligible_course_candidate'];
          mail.setTemplateId(et.id);
          Messaging.SendEmailResult [] r = 
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});   
      }   
   }
}

我设法从原来的问题中解决了这个问题,

只是想分享,

由于

1 个答案:

答案 0 :(得分:9)

我设法解决了这个问题并发送了电子邮件,

我已更新代码,

即。上面的代码