Using Apex
, how can I get the body of files uploaded using Chatter? I want to send the document with web service methods.
-
It will be helpful to get some more information. What code do you have today? Are the web-services written by you? not you? not yet?– SaarikoCommented Oct 17, 2012 at 10:46
3 Answers
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
-
Hi thx you for your answers, but i have a other problem with this! When i upload a file from the directory (and save it as ans attachment) and send it with REST webservices, it works great, but when i get a file from Salesforce it doesn't work... i tried to change the type of the file etc etc but it still doesn't work Do you have an idea? thx!– NHLCommented Oct 23, 2012 at 7:40
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
an ApexClass
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.
ContentData is no longer a query-able field in API version 33 +
-
1Mark, your answer would be much more meaningful if you could also explain the alternative field(s) or object(s) to query now. Commented Jun 7, 2017 at 9:35