You need to sign in to do that
Don't have an account?
pranavshah
Custom Email Template Issue in Apex Class in Salesforce
Dear All,
I have an requirement where i have to send an mail dynamically to user once review record get created.
I have created custom HTML Email Template but in blank body is going...
i am not getting html template which i have created
Below is the code which have written
EmailTemplate template = [SELECT Id,Name,Description,HtmlValue,Body,Subject,DeveloperName
FROM EmailTemplate WHERE DeveloperName='Review_Email_Notifications'];
System.debug('templates@@@'+template);
String emailSubject = template.Subject;
String emailTextBody = template.Body;
if(!usersObjList.isEmpty()) {
for(user emails : usersObjList){
//String emailSubject = template.getSubject();
//String emailTextBody = template.getPlainTextBody();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// String[] toAddresses = new String[] {emails.email};
//mail.setSenderDisplayName('Administrator');
// mail.setToAddresses(toAddresses);
mail.setSubject(emailSubject);
mail.setPlainTextBody(emailTextBody);
//mail.setTreatBodiesAsTemplate(true);
//mail.setplainTextbody(emailTextBody);
mail.setWhatId(varReview.id);
mail.setTemplateId(template.Id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(emails.id); //0030m00000aeYpdAAE
//mail.setTargetObjectId(ReviewId); //0030m00000aeYpdAAE
Messaging.SendEmailResult[] results=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
please help
I have an requirement where i have to send an mail dynamically to user once review record get created.
I have created custom HTML Email Template but in blank body is going...
i am not getting html template which i have created
Below is the code which have written
EmailTemplate template = [SELECT Id,Name,Description,HtmlValue,Body,Subject,DeveloperName
FROM EmailTemplate WHERE DeveloperName='Review_Email_Notifications'];
System.debug('templates@@@'+template);
String emailSubject = template.Subject;
String emailTextBody = template.Body;
if(!usersObjList.isEmpty()) {
for(user emails : usersObjList){
//String emailSubject = template.getSubject();
//String emailTextBody = template.getPlainTextBody();
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// String[] toAddresses = new String[] {emails.email};
//mail.setSenderDisplayName('Administrator');
// mail.setToAddresses(toAddresses);
mail.setSubject(emailSubject);
mail.setPlainTextBody(emailTextBody);
//mail.setTreatBodiesAsTemplate(true);
//mail.setplainTextbody(emailTextBody);
mail.setWhatId(varReview.id);
mail.setTemplateId(template.Id);
mail.setSaveAsActivity(false);
mail.setTargetObjectId(emails.id); //0030m00000aeYpdAAE
//mail.setTargetObjectId(ReviewId); //0030m00000aeYpdAAE
Messaging.SendEmailResult[] results=Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
}
}
please help
Anudeep (Salesforce Developers)
Can you try with a simpler version of code to narrow this down?