ContentDocumentLink filter error on ContentDocumentID using IN clause

the solution is to add your keySet() from Map to a new Set() and use that in the query filter using IN:

Ex:

Set<Id> newSet = mapOfContentVersion.keySet();


[SELECT ContentDocumentID, LinkedEntity.type, LinkedEntityId 
                                    FROM ContentDocumentLink 
                                    WHERE ContentDocumentID IN: newSet ]

**This worked for me today


This must be a recent update (this year), because I had code working filtering on a Set with no problem, and suddenly noticed today it no longer worked. I resolved the issue by first casting the Set to a List; see below.

    // Get content document links
    List<ContentDocumentLink> contentDocLinks = [
        SELECT
            ContentDocumentId
        FROM
            ContentDocumentLink
        WHERE
            LinkedEntityId IN :stipRecordIds
    ];
    Set<Id> contentDocIds = new Set<Id>();
    for(ContentDocumentLink contentDocLink : contentDocLinks) {
        contentDocIds.add(contentDocLink.ContentDocumentId);
    }
    List<Id> contentDocIdList = new List<Id>(contentDocIds);

    // Get the actual files
    List<ContentVersion> contentVersions = [
        SELECT
            Id,
            ContentUrl
        FROM
            ContentVersion
        WHERE
            ContentDocumentId IN :contentDocIdList
            AND
            IsLatest = True
    ];

In addition to @harish answer, the underlying problem is similar to using object.field notation as bind variables in dynamic SOQL - even though the use case is static SOQL

For static SOQL - does not work

[select COUNT() from ContentDocumentLink where LinkedEntityId = :someObj.Id]

For static SOQL, does work

ID filter = someObj.ID;
[select COUNT() from ContentDocumentLink where LinkedEntityId = :filter]

That is, filter works because it is a simple variable and not located via an object reference (e.g. someObj.Id)