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
mahimmahim 

Send an email from apex and subject and body should use from email templates

Hi,

I would like to send an email to users from apex, I am not able to use setWhatId() beacuse this will work with only contact but not user.

Is there any way can we send an email from apex?

1) I don't want to create a dummy account 
2) Don't want create body beacuase there are many tempaltes alreay created in my app i would like to reuse 
 
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Use Messaging.SingleEmailMessage, You need not use contact in setWhatId, you can set the record id as what id and targetobjectid as the owner of the record. 
Use setTemplateId() to use an existing template, just pass the id of the template to this method.