Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

You can't make it directly. 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.:

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.

share|improve this answer
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 Jan 11 '13 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 Jan 11 '13 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 Jan 17 '13 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 Jan 17 '13 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 Jan 17 '13 at 21:21
up vote 1 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.