anusha(salesforce developer)

Wednesday 20 July 2016

Sending email with template using trigger

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});   
      }   
   }
}

No comments:

Post a Comment