Querying Top contents:

select id, Title, Description, FileType,FeaturedContentDate,FeaturedContentBoost, Owner.Name, VersionNumber, ContentDocumentId,TagCsv from ContentVersion where FeaturedContentDate=null and FeaturedContentBoost=null Order By CreatedDate Desc LIMIT 10

I need to get top contents by number of downloads. Number of download option is available in content version history.

How can I include the download option in my content version query?

enter image description here


Following code works for me:

 ID cvid;
 for (AggregateResult ar: [SELECT ContentVersionId cvid, Count(ID) total FROM 
     ContentVersionHistory WHERE Field = 'contentVersionDownloaded'
GROUP BY ContentVersionId ORDER BY Count(ID) DESC LIMIT 10
  ]) {

    cvid = String.valueOf(ar.get('cvid'));

for (ContentVersion content: [select id, Title, Description, FileType, 
    FeaturedContentDate, FeaturedContentBoost, Owner.Name, VersionNumber, 
ContentDocumentId, TagCsv from ContentVersion
where ID IN: totalset 
 Order By CreatedDate Desc LIMIT 10
  ]) {

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.