Sending email with template using trigger
Asked Answered
S

1

9

I have the following 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});   
      }   
   }
}

I managed to fix this from its original problem,

And just wanted to share,

Thanks

Skilken answered 11/6, 2013 at 15:18 Comment(0)
S
10

I managed to fix it and send the email,

I have updated the code,

i.e. the code above works

Skilken answered 11/6, 2013 at 17:9 Comment(1)
What kind of template is 'Invitation_to_register_for_Class'? Is it Custom, HTML, Text or VisualForce? I'm trying to get a VisualForce template to work, but I can't get it to work via a workflow or a trigger. I receive an empty email.Aliment

© 2022 - 2024 — McMap. All rights reserved.