[SalesForce] How to i get Thumbnail Image depending on files of chatter

First of all i have a question how will i pull my files that i find in chatter Tab for community user through Chatter Connect In APEX or REST API?

And Also I need to display Icon based on image .Lets say if its word doc then a word doc image Icon should appear and similarly image of pdf ,if its pdf file .

Best Answer

If you need to pull only your files then you will need to query the ContentVersion Standard Object.

ContentVersion documentation

ContentVersion is the standard object where each revision of a document is stored in Salesforce Content. Chatter files are also stored as ContentVersions.

It has a field called FileType that returns the type of content determined by ContentUrl for links or PathOnClient for documents. That will help you to determine what icon to display depending on the file type.

You can do a query like the following:

List< contentVersion = [SELECT Id, FileType, Title, ContentUrl, PathOnClient, VersionData from contentVersion WHERE OwnerId =: UserInfo.getUserId()];

VersionData is the field that has the encoded file data.

I would like to mention that Chatter REST API provides the following resource that allows you to get information about a list of files:

/chatter/files/batch/fileIds

Hope it helps!

Related Topic