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

how to pass values to merge fields in Email templates from apex class
hi
i created a new Email Template of type Custom or Visualforce or Text.
The following case has been assigned to you.
Company: {!Account.Name}
Contact Name: {!Contact.Name}
Case #: {!Case.CaseNumber}
Subject: {!Case.Subject}
Description: {!Case.Description}
Company: {!Account.Name}
Contact Name: {!Contact.Name}
Case #: {!Case.CaseNumber}
Subject: {!Case.Subject}
Description: {!Case.Description}
i write an apex class for calling this email template and sending an email.
i am sending an email to the User.
But i dont know how to pass values to Merge fields(ex: {!Account.Name}) in that email template from an apex class.
How can i pass values to merge fields in Email template.
Message Edited by PRepaka on 11-25-2008 05:00 AM
Thanks
Ben
I also need an answer to this question. Can anyone help us out?
Thanks.
hi,
i am also facing the same issue...Can any one suggest a way..!!
I believe if the email is being sent from Apex, the only way to do this is to specify the "Who Id" and "What Id". Salesforce will populate the {!fields} based on the records specified in those fields. In the Email Message Methods in Apex, use the setWhatId and setWhoId methods.
I need the solution for the same question . is there any one who got the solution or else the way for the solution please do post it
Rohit,
Please see my previous post. I believe the only way to do this is to set the whoId to a contact Id and the whatId to another object that has activities enabled. You might also be able to try Visualforce templates, but you'd have to look up the documentation for that.
You can use String.replace() to insert values to your email template.
for example:
EmailTemplate emailTemplate = [SELECT Id, body, HtmlValue, Subject
FROM EmailTemplate
WHERE DeveloperName = 'email template name....' LIMIT 1];
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String body = emailTemplate.HtmlValue;
body = body.replace('{!Account.Name}', 'value.....');
body = body.replace('{!Contact.Name}', 'value....');
email.setHtmlBody(body);
email.setTemplateId(emailTemplate.Id);
email.setSaveAsActivity(false);
email.setTargetObjectId(users[0].Id);
List<String> usersEmails= new List<String>{'email@gmail.com','xxx@gmail.com'}; //list of emails to sent to
email.setToAddresses(usersEmails);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email});
I know it is a old thread but I need some help on this
If we are sending the mail using this replace functionality, there is a chance of getting Special Characters at the end of email template becoz we are converting the template to HTML format... will please help me out how to resolve this issue..
Thanks in Advance.........