2

I have the following code:

// Note: cdlToDos == Map<Id, Set<decimal>>

System.debug(cdlToDos);
List<ContentDocumentLink> cdlList = [
    SELECT Id, ContentDocumentId, LinkedEntityId
    FROM ContentDocumentLink
    WHERE ContentDocumentId IN : cdlToDos.keySet()
];
System.debug(cdlList);

Which produces the following output:

DEBUG|{0693B000000fwAbQAI={163}}
DEBUG|()

HOWEVER...when I run the following query through workbench:

SELECT Id, ContentDocumentId, LinkedEntityId
FROM ContentDocumentLink
WHERE ContentDocumentId IN ('0693B000000fwAbQAI')

I get two results.

Both workbench and Apex are using the same user context. Is there something I'm missing here that prevents the Apex query from working?

  • 2
    Are you running the Apex from Execute Anonymous or in a class elsewhere? – David Reed Jan 6 at 23:18
  • Sorry, I should have mentioned that this is in the ContentDocument trigger (after insert). The requirement is to complete various "To Do" items when documents with certain titles are attached to an Opportunity. (edit) The issue is that ParentId doesn't always get populated in ContentDocument, so I also have to look in ContentDocumentLink for the record ID. – Ixalmida Jan 7 at 15:15
1

I think I just figured this out. The ContentDocumentLink probably doesn't get committed until after the ContentDocument Trigger runs. Thanks to David Reed for the hint.

It looks like I'll have to build my own file management lightning component so I can explicitly pass the record ID to an Apex controller. Its a shame that Salesforce makes it so hard to customize the default file management process.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.