+ Start a Discussion
Mike ChandlerMike Chandler 

SOQL query returns no results Trigger but returns a row in Developer Console

I have the following code snippet in a Helper class that's being called by an After Insert trigger (modified to demonstrate my objective):
Set<Id> reuseIds = new Set<Id>();

List<ContentDocumentLink> allLinks = [SELECT Id, LinkedEntityId, ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId IN :reuseIds];

System.debug('allLinks size: ' + allLinks.size());

The debug output is showing me that I'm getting zero results. However, when I run the same query in the debug console, I see the single row returned that I'm expecting.

I have included without sharing on the trigger Helper class even though my understanding is that's not necessary in a trigger, but it doesn't change my results.

Can anyone offer any clues as to what I may be experiencing here?
paul diracpaul dirac

Does executing that script in the anonymous window retrieve the record or not?

I will also try to hardcode the 15 digits Id instead of the 18 digits one ('0R000001VnjMQAS') 

Mike ChandlerMike Chandler
I fooled myself into believing that it didn't work in an anonymous window by running this in the wrong environment. However, I just ran it in the correct environment and it DOES in fact come back with the expected record in an anonymous window.
paul diracpaul dirac
Actually that was so strange ;)