I have a component and apex controller that calls/displays all the related files on a record.

How can I filter the returned files by a field that is set on ContentVersion?

ie. only show files if Document_Type__c = Supporting Document

Apex controller:

public class SimplyfyFilesCntrl {  
   public static List<ContentDocument> getFiles(string recordId){  
     List<ContentDocument> DocumentList = new List<ContentDocument>();  
     Set<Id> documentIds = new Set<Id>();  //store file ids
     List<ContentDocumentLink> cdl=[select id,LinkedEntityId,ContentDocumentId from ContentDocumentLink where LinkedEntityId=:recordId];  
     for(ContentDocumentLink cdLink:cdl){  
       documentIds.add(cdLink.ContentDocumentId);  // Document ids
     DocumentList = [select Id,Title,FileType,ContentSize from ContentDocument where id IN: documentIds];  
     return DocumentList;  


You will have to get the LatestVersionId from the ContentDocument then get the ContentVersion entity and the custom field you want.

| improve this answer | |

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.