5

I am trying to query ContentVersions based on the related ContentDocument Ids and getting 0 results returned even when the user can access the file in the user interface and there is a ContentDocumentLink record sharing out the file.

1 Answer 1

2

Contentversion queries return 0 results if you are using a set of IDs (SF Bug) rather than a list of IDs so you must always use lists.

//set of IDs always returns 0 results
set<ID> testidset = new set<ID>{'06917000000CfroAAC','06917000000CfrqAAC'};
list<Contentversion> cvtestidset = [Select Id from ContentVersion where ContentDocumentId in :testidset];
system.assertequals(0,cvtestidset.size());

//same ids
list<ID> testidlist = new list<ID>{'06917000000CfroAAC','06917000000CfrqAAC'}; 
list<Contentversion> cvtestidlist = [Select Id from ContentVersion where ContentDocumentId in :testidlist];
system.assertequals(2,cvtestidlist.size());

Also, if you query the versiondata field on ContentVersion you CANNOT query those contentversion records again. It appears to be some sort of bug with query caching when using base64 fields as querying for different contentversion records will work correctly but running the same query again returns 0 results.

list<ID> testidlist = new list<ID>{'06917000000CfroAAC','06917000000CfrqAAC'};

list<Contentversion> cvtestidlist = [Select Id, VersionData from ContentVersion where ContentDocumentId in :testidlist];
system.assertequals(2,cvtestidlist.size());

list<Contentversion> cvtestidlist2  = [Select Id from ContentVersion where ContentDocumentId in :testidlist];
system.assertequals(0,cvtestidlist2.size());

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .