3

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>();
reuseIds.add('a0g0R000001VnjMQAS');

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?

enter image description here

  • 1
    What object is the trigger on? – Kris Goncalves Jan 22 at 23:54
  • 1
    You are saying that you execute this SOQL on a helper class from an after insert trigger. The ContentDocumentLink "Represents the link between a Salesforce CRM Content document or Salesforce file and where it's shared." You probably don't have any ContentDocumentLink related to the new inserted record? – Carlos Naranjo Jan 23 at 0:20
  • 1
    what's the ShareType value in the row returned in the query in dev console? – Kris Goncalves Jan 23 at 1:10
  • 1
    Is your trigger helper “with sharing”? – Sebastian Kessel Jan 23 at 4:31
  • 1
    What user are you running as when you test it via the trigger? If it's a community or guest user, then files are hidden even "without sharing" unless they are explicitly shared. I imagine (but don't know for sure) that this applies to ContentDocumentLink, too. – Aidan Jan 23 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.