You need to sign in to do that
Don't have an account?

Visualforce Email Template in apex code.
I have created a visualforce email template which is related to a custom object and recipient type is user. I am using this template in apex code to send the email but it does not send any email while the same email template shows correct merge field etc in case of preview.
i am using the following code to send the email
Messaging.SingleEmailMessage mail = mail.setTemplateId(templates[0].Id);
//currently loggoed in user's Id, getting value from UserInfo.getUserId()
mail.setToAddresses(mail.setTargetObjectId(currentUser.Id);
mail.setWhatId(record.Id); //a custom object record id
mail.setSaveAsActivity(false);
mail.setReplyTo(senderEmail); //its valid email id
mail.setSenderDisplayName(senderDisplayName);
Messaging.sendEmail(
new Messaging.SingleEmailMessage[]{mail});When i use debug log, it show a mail in email queue still its not sending any email.
so could any one tell me that where i am commiting a mistake??
Is it complete code?
mail.setTemplateID seems to be missing.
Actually it was there in the original code but while posting the code here. i have commited some mistake.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId(templates[0].Id);
meanwhile i have tried to send email by workflow using the same Email Template and it was working so i dont understand that why it is happening??
Why are you doing this?
setTargetObjectId is a void method. How were you able to compile that code??
Did you find any solution?
I am stuck in the same scenario