function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JBabuJBabu 

Need help on Email Templates question

hi
 
I have 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} 
 
I have written 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 (mentioned above) in that email template from an apex class. 
 
How can I pass values to merge fields in Email template? Please help me out.
Thanks,
JBabu.
Best Answer chosen by Admin (Salesforce Developers) 
SRKSRK

Try this

mail.setTargetObjectId(con.Id);     // con.id is the ID of the record that u want to us in email tamplate
                                                   // for ex if i want to send email on my account test whos id is 00142GHBSH453EO

                                                    then i write mail.setTargetObjectId('00142GHBSH453EO');

 

mail.setTemplateId('00X90000000QHUD');   // U r email tamplate

All Answers

SRKSRK

Try this

mail.setTargetObjectId(con.Id);     // con.id is the ID of the record that u want to us in email tamplate
                                                   // for ex if i want to send email on my account test whos id is 00142GHBSH453EO

                                                    then i write mail.setTargetObjectId('00142GHBSH453EO');

 

mail.setTemplateId('00X90000000QHUD');   // U r email tamplate

This was selected as the best answer
JBabuJBabu

Thank you SRK.

SRKSRK

Welcome friend :)