Introduction
This error may take place while querying ContentDocumentLink and filtering it with IN operator. Sometimes, it shows a weird behaviour and throw below 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.”
Possible Reasons
- Check Set/List is not empty
List<ContentDocumentLink> links = [SELECT ContentDocumentID, LinkedEntity.type, LinkedEntityId
FROM ContentDocumentLink
WHERE ContentDocumentID IN: newSet];
Add check as below:
if(!newSet.isEmpty){
List<ContentDocumentLink> links = [SELECT ContentDocumentID, LinkedEntity.type, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentID IN: newSet];
}
- Create a simple variable and use as filter:
List<ContentDocumentLink> links = [SELECT ContentDocumentID, LinkedEntity.type, LinkedEntityId
FROM ContentDocumentLink
WHERE ContentDocumentID =: Obj.DocId];
Change as below:
String documentId = Obj.DocId;
List<ContentDocumentLink> links = [SELECT ContentDocumentID, LinkedEntity.type, LinkedEntityId
FROM ContentDocumentLink
WHERE ContentDocumentID =: documentId];
- As last step, use direct set/list instead using map.keyset:
List<ContentDocumentLink> links = [SELECT ContentDocumentID, LinkedEntity.type, LinkedEntityId
FROM ContentDocumentLink
WHERE ContentDocumentID =: docmap.keySet()];
Change as below:
Set<String> docIds = docmap.keySet();
List<ContentDocumentLink> links = [SELECT ContentDocumentID, LinkedEntity.type, LinkedEntityId
FROM ContentDocumentLink
WHERE ContentDocumentID =: docIds];
Conclusion
Feel free to reach out in case of any help needed.