0

I am trying to send emails through email template in my apex class . This is the code I am trying

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(emailaddress);
mail.setTargetObjectId(user.id);
mail.setTemplateId('00Xf0000000cE9E');//template salesforce id 
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {
            mail
         });
           } 

I am still not able to figure out where can I use approval id so that the values in template fetches details as per that .

My email template uses Approval related details such as approval.name,approval_status etc and displays it in a table .

Now I am trying to pass the template in the trigger which fires when status is updated to submitted or rejected or cancelled .So i am using trigger.new[0].id which is approval id in the trigger .So how can I pass this id so that template fetches approval related details on the basis of it .

Also if I use email templates can I send it to external ids too in apex because there is a set.targetobjectid() method which takes ids of salesforce users . not sure how to bypass this mandatory targetobjecid

  • This question needs some elaboration. What does your email template look like and what triggers this Apex code. Use edit, not comments to elaborate. – cropredy Dec 5 '19 at 17:51
  • @cropredy thanks for asking . Please check now – user75937 Dec 6 '19 at 5:11
  • please use edit and add in the email template (is it VF?) - just the first line and a couple of relevant merge fields. Is there a WhatId/relatedToType? – cropredy Dec 6 '19 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.