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