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
SforcehariSforcehari 

Visualforce Email Templates,Require help.

Hai to Salesforce,

 

 I want to send an email alert to user when the task is overdue, unfortunately we don't have option to send  overdue email through workflows, so the only option is Apex code and Visualforce email template,but i have searched enire to get about Vfemail templates, but i didn't get needed information forme,

 

 please help me , I am creating Vfemail template sucessfully,and in verify test and getting merge fields also,

 

 Now i am having doubt like, how we can send that Email template to User through Trigger and how i can pass record ID to that template in trigger. please help me

 

Regards,

Haribabu

Best Answer chosen by Admin (Salesforce Developers) 
osamanosaman

Try using this:

 

 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setTemplateId(EmailTemp.Id);

  mail.setSaveAsActivity(true);

 mail.setReplyTo('123@213.com);         

 mail.setSenderDisplayName('Sender');

mail.setWhatId('AssociateId');                   

mail.setTargetObjectId('Contact OR Lead ID');

 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

All Answers

osamanosaman

Try using this:

 

 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setTemplateId(EmailTemp.Id);

  mail.setSaveAsActivity(true);

 mail.setReplyTo('123@213.com);         

 mail.setSenderDisplayName('Sender');

mail.setWhatId('AssociateId');                   

mail.setTargetObjectId('Contact OR Lead ID');

 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

This was selected as the best answer
SforcehariSforcehari

Hai  Osaman,

 

     I too Know this, WHat i am asking is, i have used merge fields in that template,how we can pass the current record ID to that Email template, so that i can get data in to my template.

 

 Regards,

Haribabu

osamanosaman

You need to set the Target Object Id field to set the current record.

SforcehariSforcehari

Thank you for Quick response,

 

  From where i can send that ID, how i can ?If you have any sample please send it to me.

 

Regards,

Haribabu.

osamanosaman

Thats what I included in my first post

 

mail.setTargetObjectId('Contact OR Lead ID'); // You need to set this Id with a contact or lead object. Since the user is actually the owner of one of these records, the merge field will pick up the vlaue.

 

mail.setWhatId('Account, Opportunity or any related object Id'); //if you have placed merge fields with opportunity/quote or any other related object owner.

SforcehariSforcehari

Hai ,

 

I need to Pass Task iD , how i can.I am populating taskfields,how i can.

 

Regards,

Haribabu.

osamanosaman

Set the task Id here mail.setWhatId()