Using Apex, how can I get the body of files uploaded using Chatter? I want to send the document with web service methods.
Best Answer
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
So, I haven't actually tried this, but here's what I would try first:
FeedItem myPost = new FeedItem();
myPost.Parentid = object.Id; //user's Id I'm assuming
myPost.body = 'Text here http://www.internets.com more text http://www.theinternets.com';
insert myPost;
Obviously, you'd have to get the Id of the object you're posting to and the links to the contact and opportunity.
You have uncommitted work pending. Please commit or rollback before calling out
this means that you make a (rest) webservice call, after you started a database transaction, either you do your webservice call before doing DML statements, or you do your webservice call in an @future method.
Best Answer
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