I am trying to get list of all the ContentDocumentLink which are not available in a set. But when I try to get NOT IN its giving error Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator. But when I remove NOT form the query it is working. I tried the same NOT IN for attachment SOQL here it works perfectly. Do anyone have any idea why this is not working with NOT IN condition in SOQL.

Attachment Code

attLst = [SELECT Id, Name, body, ParentId FROM Attachment WHERE ID NOT IN : transfer.keyset()];

ContentDocumentLink Code

global void execute(Database.BatchableContext bc, List<sObject> scope){
    List<ContentDocumentLink> contDoc = new List<ContentDocumentLink>();
    Map<String, Transfer__c> transfer = new Map<String, Transfer__c>();
    for(Transfer__c trans : [SELECT File_Attachment__c, Transfered__c FROM Transfer__c WHERE Transfered__c = true ]){
        transfer.put(trans.File_Attachment__c, trans);
    contDoc = [SELECT ContentDocumentId, LinkedEntityId  FROM ContentDocumentLink WHERE ContentDocumentId NOT IN : transfer.keyset() ];

1 Answer 1


This is an implementation restriction on Content objects. You simply can't run unrestricted or negative queries against ContentDocumentLink. You must query that object using an = or IN clause, as the error message specifies.

You'll probably need to rethink your logic to work in terms of ContentDocument instead, and you may need to consider running the automation in the context of a user who has Query All Files permission if you need to be able to query every Content record in your org. Once you acquire ContentDocument Ids, you can query ContentDocumentLink records if you still need to.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .