Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

2 Answers 2

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.

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). –  user1193 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. –  user1193 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}); –  user1193 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 0 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

 
discard

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.