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
Vijay NagarathinamVijay Nagarathinam 

Unable to save the email in the Activity History

Hi,

Currently, I am using apex code to send an email to a specific user. I want to add the email in the activity history. Is there any way to add the emails to the activity history related list.
 
Messaging.EmailFileAttachment emailFileAttachment = new Messaging.EmailFileAttachment();
emailFileAttachment.setFileName(attachFile.Name);
emailFileAttachment.setBody(attachFile.Body);
emailFileAttachment.setContentType(attachFile.ContentType);
emailFileAttachment.setInline(false);
email.setSaveAsActivity(true);
email.setReplyTo(Label.From_Address);
email.setSubject('Application submitted documents ');
email.setHtmlBody('Test');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });



Thanks,
Vijay
sachin sabusachin sabu
Hi vijay,
 
u need to use  setTargetObjectId(targetObjectId) to add email as activity history.
mail.setTargetObjectId(toaddress);


 
Vijay NagarathinamVijay Nagarathinam
Hi Sachin,

The setTargetObjectId method supports Lead, Contact and User objects only. But I am using custom object to add the email in the history.

Thanks,
Vijay