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
TechBlossomTechBlossom 

custom email

I have created a visual force page and controller for email functionality. The page can be called  from a button on a custom object Safari__c. This custom object has a look up with accounts. 

Whenever I send an email, I want the activity to be logged in the activity history of the custom object. So I am setting setSaveAsActivity to true in my controller along defining setTargetObjectId. I am assigning the current user id to setTargetObjectId. The To , Bcc and Cc fields have a look up on contacts.  Once,  a mail is sent, this action is also logged in the activity log of the account. But, the email recipients are not actually receiving any email.  The result mail does not have any errors and says that the email has been sent.
I tried sending the email without the setTargetObjectId, it works and the email recipients do get an email. But without setTargetObjectId, I cannot log the activity. 
Any workaround on this??