You need to sign in to do that
Don't have an account?

Unable to filter using ContentDocument id in query in trigger query not retrieving any results
Hi,
I have a requirement to make to make a file private and be available to only the user whose role name consists the name of the file for a specific custom object. For this I am trying to retrieve from Content Document Link with the custom object name LinkedEntity.Type and ContentDocumentid as filters, when I hard code the ContentDocumentid it is working fine but when I try to dynamically provide the ContentDocumentId then the query is not returning any result. I am adding a snippet of my code. Please Help!!. Thanks
I have a requirement to make to make a file private and be available to only the user whose role name consists the name of the file for a specific custom object. For this I am trying to retrieve from Content Document Link with the custom object name LinkedEntity.Type and ContentDocumentid as filters, when I hard code the ContentDocumentid it is working fine but when I try to dynamically provide the ContentDocumentId then the query is not returning any result. I am adding a snippet of my code. Please Help!!. Thanks
List<Id> listOfConDocuId = new List<Id>(); for(ContentVersion cv: Trigger.new){ if((!cv.Title.contains('product proposal')) || (!cv.Title.contains('final')) || (!cv.Title.contains('packet'))) listOfConDocuId.add(cv.ContentDocumentId); } Map<Id, Project__c> mapOfProjectId = new Map<Id, Project__c>([SELECT Id FROM Project__c]); Set<Id> setOfProjectId = mapOfProjectId.keySet(); List<ContentDocumentLink> LinkedProject = [SELECT ContentDocumentId, LinkedEntityId, ContentDocument.Title FROM ContentDocumentLink where LinkedEntityId in :setOfProjectId and LinkedEntity.Type='Project__c' and ContentDocumentId IN :listOfConDocuId];
What kind of trigger is it, before insert? It might be the case that at that point there's no "parent" (ContentDocument). And ContentDocumentLinks come even later in the process (first ...version and ...document has to be created, then you use ...link to connect ...document to your custom object). Run System.debug(listOfConDocuId); see if they come out as nulls or something else. If they come out null - you're starting in the wrong place and making a trigger on CDL might be a better idea.
Also, please check below link.
- https://salesforce.stackexchange.com/questions/197848/trigger-on-contentdocumentlink
Please let us know if this helps.Thanks,
Nagendra
Please check this filter LinkedEntity.Type='Project__c'. Because LinkedEntity is hold only object data.
You can filter like
SELECT ContentDocumentId, LinkedEntityId,ContentDocument.Title, ShareType, ContentDocument.OwnerId FROM ContentDocumentLink where LinkedEntityId in ( SELECT Id FROM Account)