Requirement
I have to fetch all the content Notes that are associated to events created after 01-Aug-2016.
Logic path
I have taken the following path to get to content notes
- fetch events
- find the Link via ContentDocumentLink object by passing them Event ids fetched in step-1
- fetch ContentVersion by passing ContentDocumentIds retrieved in step-2
- check each contentversion record by looking at their fileType to filter out only notes (SNOTE).
Code
Set<id> ev=(new Map<Id, Event>([SELECT id from Event where CreatedDate > 2016-08-01T00:00:00Z])).keySet();
Map<id, ContentDocumentLink> cdlMap = new Map<id, ContentDocumentLink>();
//ContentDocumentLink[] cdlList =[SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId IN : ev];
Set<id> contentDocumentIdSet = new set<id>();
for(ContentDocumentLink cdl: [SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE LinkedEntityId IN : ev])
{
cdlMap.put(cdl.ContentDocumentId, cdl);
contentDocumentIdSet.add(cdl.ContentDocumentId);
}
system.debug('cdl keys > ' + contentDocumentIdSet );
List<ContentVersion> cvMap = new List<ContentVersion>([SELECT Title, FileType, ContentDocumentId FROM ContentVersion WHERE ContentDocumentId IN:contentDocumentIdSet]);
system.debug('cdlMap ' + cdlMap.size() + '| cvMap > ' + cvMap.size());
Problem
ContentVersion list (cvMap) is not returning anything.
- I tried passing
cdlMap.keySet()
didn't work. - I then created a
Set<id>
and passed the map keyset to it and then supplied it to the SOQL, that didn't work either. and now I tried the above code to created a set in loop and provide it in SOQL. Not working.
If I hardcode ContentDocumentId to SOQL single or multiple, it is working. I wonder why it is not working in this case.