+ Start a Discussion
vanessenvanessen 

email template use from apex code

I am sending an email from apex using an email template.I can specify the object to use by my email template for the recipientType (by using the setTargetobjectId method) but how can i specifty the object to be used by my emailTemplate for the relatedTo

 

 

 

my code is the following:

 

if (!templateList.isEmpty() && userIds.contains(caseMap.get(t1.WhatId).OwnerId)){

 

 

//there is a template to be used

 

mail.setTargetObjectId(caseMap.get(t1.WhatId).OwnerId);

 

mail.setSaveAsActivity(false);

 

mail.setWhatId(caseMap.get(t1.WhatId).Id);

 

mail.setTemplateId(templateList[0].Id);

 

 

}

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

'setWhatId' refer to the relatedto.There is no method in single email and mass email messages for the relatedTo.

 

Hope this helps.

All Answers

Pradeep_NavatarPradeep_Navatar

'setWhatId' refer to the relatedto.There is no method in single email and mass email messages for the relatedTo.

 

Hope this helps.

This was selected as the best answer
vanessenvanessen

thank you very much, problem solved