You need to sign in to do that
Don't have an account?
Noodle
Visualforce Template, Scheduled Class RelatedToType
Hi there. I have a Visualforce template that I want to use to send out a weekly email.
Then I have my Scheduled Class:
I would like to test this out by inserting both UserID's like I would if I was trying to preview the template. I already have the Object Target via setTargetObjectId('userId'); . How do I set the second one?
<messaging:emailTemplate subject="Your late Tasks" recipientType="User" relatedToType="User" replyTo="cases@acme.nomail.com" > <messaging:htmlEmailBody > ............. ............. ............. .......... </messaging:htmlEmailBody> </messaging:emailTemplate>
Then I have my Scheduled Class:
global class massTaskEmail implements Schedulable { global void execute(SchedulableContext sc) { Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); email.setTemplateId('templateId'); email.setSaveAsActivity(false); email.setTargetObjectId('userId'); Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email}); } }
I would like to test this out by inserting both UserID's like I would if I was trying to preview the template. I already have the Object Target via setTargetObjectId('userId'); . How do I set the second one?
setTargetObjectId(ID) will ensure the User merge fields get the correct value.
If your case was as below:
recipientType = Contact and relatedToType= Account
Then you would use setWhatId(ID)(optional) to get the merge fields related to the account object on the contact.
reference:
http://www.salesforce.com/docs/developer/pages/Content/pages_compref_messaging_emailTemplate.htm
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm#apex_Messaging_SingleEmailMessage_constructors