We have a hosted application that runs in our datacenter. We use the Partner API to integrate our application with SFDC. When we send an email from within our application (and from our servers), we’d like to record the email history in SFDC. This email history record should include the To, Cc, Bcc, Subject, Body and attached files (just like the Activity History that I see after I send an email in the Opportunity window).

Which object and/or methods should be used to create these email history records?

3 Answers 3


You can't make it directly. http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_activityhistory.htm suggests that you can only run describe calls (compare with Account for example).

In fact simplest insert new ActivityHistory(); fails with Compile error at line 1 column 1 DML operation INSERT not allowed on ActivityHistory.

Check out this answer from the SF boards.: http://boards.developerforce.com/t5/General-Development/Adding-Activity-History-records-through-API/td-p/345713

Try Task with Type = 'Email' (which should be available in the picklist out of the box)? You might have to add your own fields for "To" address etc though.

  • I used DescribeSObject to look at the fields that are available in Event and Task. Neither contains a Type field (even though a Type field is listed for both in the documentation).
    – NHLeo
    Commented Jan 11, 2013 at 16:56
  • Try running this: Task t = new Task(Subject = 'demo', Type = 'Email', Status = 'Completed'); insert t; System.debug(t.Id);. Tested in Developer, Enterprise & Unlimited Editions, I don't believe there's an edition without the fields...
    – eyescream
    Commented Jan 11, 2013 at 19:58
  • I performed an equivalent operation in C# and got an error ("Task: bad field names on insert/update call: Type"). You can see the code below.
    – NHLeo
    Commented Jan 17, 2013 at 21:07
  • sObject eventObj = new sObject(); eventObj.type = "Task"; List<XmlElement> fieldsToUpdate = new List<XmlElement>(); fieldsToUpdate.Add(MakeFieldElement("Subject", "This is a test ...")); fieldsToUpdate.Add(MakeFieldElement("Type", "Email")); fieldsToUpdate.Add(MakeFieldElement("Status", "Completed")); eventObj.Any = fieldsToUpdate.ToArray(); SaveResult[] result = null; result = _sfdcBinding.create (new sObject [] {eventObj});
    – NHLeo
    Commented Jan 17, 2013 at 21:08
  • This is crazy :) Is the integration user a System Administrator? If not -can you log in to the web interface, go to setup->customize->activities->task fields and verify that his Profile is ok in the "view field accessibility"? You might have to a) Contact SF support, looks like platform bug b) make your own Type__c field c) expose some stupid Apex webservice that'd be making these Tasks? Geez... And what if you query the table looking for existing Tasks?
    – eyescream
    Commented Jan 17, 2013 at 21:21

I realized that we had worked out the answer to this problem without updating this question.

The answer really comes down to a newbie configuration issue. In the developer orgs that Salesforce provides, the Type field on the Task object is not visible. Once we went into the Setup and made the Type field in Task visible for all the appropriate profiles, everything started working just fine.


the answer of eyescream is correct but you need to create the task and use the TaskSubtype property. In my case I created the Task like this

Task task = new Task(); task.OwnerId = object.OwnerId; task.TaskSubtype = 'Email'; task.Status = 'Completed';
task.WhoId = object.Id; task.Subject = 'subject'; task.Description = 'description'; insert task;

in this way you will create an Activity History of type Email ad you can filter by Email in the activites list (or in the parent object like Lead, Account, etc) and you will be able to see it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .