function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
davidleckenbydavidleckenby 

SOQL Query within Apex Scheduled Job

I have a trigger that fires on the ContentDocumentLink object that then calls a REST Webservice. The logic basically places a users document into our Document Management System from Salesforce and then deletes the original file (whilst returning the link to it). Everything is working fine. Within the trigger context I have the Trigger.new collection that I can query against and use in as a part of my code.
I am now wanting to replicate this logic but as part of a scheduled job. The logic is that if the trigger doesn't work for whatever reason (web server not available etc) then the files remain within Salesforce and then every hour this batch job will run collect all of the records that didn't work and then repeat the exercise to try to get the files across to the DMS.
So essentially what I need is to be able to query the ContentDocumentLink object and pull back a list of records that I need. Its proving to be a more difficult task to do and I am getting the following 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."
How am I able to get a collection of records that I can work with? - Many thanks :)
Best Answer chosen by davidleckenby
Raj VakatiRaj Vakati
ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator.
ConvertAttachmentsToFilesServiceTest: 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.


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


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