I have template which is based on the merge fields related to order line items. I want to use this template in apex to send a mail,but using TagetObjectId: which expects the value to be user/contact/lead it : am unable to establish a context for template.
On testing, if i hard code the targetObject Id with some user Id,am able to get the emails-but the template referred merge fields are not populated.
How can i achieve to populate these merge fields properly.?
- create a new Messaging.singleEmailMessage()
- setTargetObjectId(a valid contactid)
- setWhatId(Id of order line item)
- setTemplateId(id of my email template based on orderline item)
- setSaveAsActivity(false)
- Messaging.sendEmail(emails, false)