SingleEmailMessage - send email to a recipient different from the record referenced by setTargetObjectId

Now we can use setTreatTargetObjectAsRecipient(treatAsRecipient) and treatAsRecipient as false.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm


Always templateId and targetObjectId walk hand in hand. If templateID is specified - email will always go to leadId

If you remove templateId- email will go to [email protected]


Setting setTreatTargetObjectAsRecipient to false does the trick,

BUT

It does not save as an activity on that target.