Find your content:

Search form

You are here

Overcoming ContentDocumentLink single Contact restriction

 
Share

I have a list of FeedItems I am iterating over. These are FeedItems for a List of Contacts that represent posts to their walls.

Some of these posts are of type ContentPost, which basically means someone posts a file to their wall. In the standard SFDC Chatter feed, this comes with a nice shiny icon and a link to the file.

From researching, I found out that the only way to get the id of the file is to use the ContentDocumentLink object, where the LinkedEntityId is the id of the contact.. I constructed the following query:

List<ContentDocumentLink> cdls = [Select ContentDocumentId, LinkedEntityId from ContentDocumentLink where LinkedEntityId = in :contactIds];

But got the following error:

Implementation restriction: ContentDocumentLink requires a filter by a single Id, ContentDocumentId or LinkedEntityId using the equals operator.

I tried with a hardcoded contact and it worked just fine.

The only solution I can think of is doing an SOQL query for every Contact that is in my List, which runs into limits issues. If this is the case, then Salesforce really didn't think through the ContentDocumentLink object very well. I would like to know if there are any alternatives before going down the 1 SOQL per Contact route.

Thanks in advance.


Attribution to: George S.

Possible Suggestion/Solution #1

ContentDocumentLink is not the only way to get the ID of this file. You can run the following query to get the ids of all the contentversion records:

Select RelatedRecordId, ID From FeedItem where Type = 'ContentPost'

Then you can run a query on the contentversion and related contentdocument to get all the information you need.

Select Title, ContentUrl, ContentDocument.Title, ContentDocumentId From ContentVersion

The ContentDocumentLink is kind of like the object__share equivalent for files so what you can do with them is strictly limited for the moment. The query restrictions are here and there is also a restriction that you can not create ContentDocumentLinks that link to a record.


Attribution to: Greg Grinberg
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1701

My Block Status

My Block Content