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
AbAb 

Adding a Task(email type) to a record of a custom object

Hello,

Using Apex code, I want to add a task "send email" to a activity history for a custom object.
The fields i have in the email are 
To
Subject
Body
Attachment
Parent Id
With the above value how can i add them to the activity history ?
 
Best Answer chosen by Ab
Pankaj_GanwaniPankaj_Ganwani
It should be added. Also specify the 'Type' field value as 'Email'.

insert new Task(Status = 'Completed', Type='Email', Whoid=con/leadId, WhatId = customobjectId);

All Answers

Pankaj_GanwaniPankaj_Ganwani
Hey Sandrine,

Just create with 'Completed' status.
insert new Task(Status = 'Completed');


Fill rest of the fields as well.
AbAb
Its not still added as email type. I want to add a task as email and the details of the email from Apex.
Pankaj_GanwaniPankaj_Ganwani
It should be added. Also specify the 'Type' field value as 'Email'.

insert new Task(Status = 'Completed', Type='Email', Whoid=con/leadId, WhatId = customobjectId);
This was selected as the best answer