WHY Can't I Use SetTargetObjectId(UserId) and SetWhatId?
When I was faced with this, I
- Had a fixed Contact record with firstname = null, lastname =
ErrorNotificationsDoNotDelete
, email =[email protected]
under a known AccountMyCompany *do not delete*
- Used the the running User's email as the 'to:' address in the Apex outbound email message
- Used the ID of the aforementioned Contact as the
targetObjectId
thereby enabling thewhatId
to be my object with the error details. The contact's Id was managed in a custom setting.