7

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? – Saariko Oct 17 '12 at 10:46
3

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! – NHL Oct 23 '12 at 7:40
6

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

  1. I believe SOQL will return only 1 row because it contains a base64 column in the results.
  2. 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.

  • Thx for the advices! – NHL Oct 23 '12 at 7:27
0

ContentData is no longer a query-able field in API version 33 +

  • 1
    Mark, your answer would be much more meaningful if you could also explain the alternative field(s) or object(s) to query now. – Samuel De Rycke Jun 7 '17 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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