Apex, how can I get the body of files uploaded using Chatter? I want to send the document with web service methods.
You need to query FeedItem where the Type is 'ContentPost' and grab the ContentData
SELECT Id, Type, Body, Title, LinkUrl, ContentData, ContentSize, ContentFileName, ContentType From FeedItem where Type = 'ContentPost' order by createddate, ID DESC
Here's the reference doc : http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_feeditem.htm
If you query the ContentData column from the FeedItem object you should return a base64 encoded version of the file.
Keep in mind the following
- I believe SOQL will return only 1 row because it contains a base64 column in the results.
- Chatter supports files up to 2GB in size, so...
a. Watch your heap size, the base64 file may be bigger than the permitted heap for
b. Theres a max size on an outbound webservice call, and a maximum time to send it.
Personally, it'd be better if you queried Salesforce from the outside over the REST/SOAP API and then posted the file to the web service.