0

I'm able to query ContentVersion, ContentDocument and other Content objects but I'm unable to find the relationship from File to an object, for instance Opportunity.

I'm working on exporting these using Force.com .Net toolkit, but without knowing which Opportunity, or Custom Object parent its from I'm pretty much treading water here.

What am I missing?

I can clearly see the Files related list populated in the Opp page layout, but when I query ContentDocument or ContentVersion, I can't find that relationship to the Opportunity Id, just the owner Id.

I'd greatly appreciate any insight.

2
  • 1
    Does this answer your question. Seems a duplicate of this question May 21 '20 at 15:21
  • 1
    I think you're right. This may be the clue I was looking for: "There can be multiple entries for each ContentDocument. In the case of attachments (Lightning uses ContentDocument for attachments), there will be a record in the ContentDocumentLink for both the UserId and the record that is the Attachments Parent." May 21 '20 at 16:05
2

There is a junction object called ContentDocumentLink, the LinkEntityId field contains the Id of the parent record.

See the object model for ContentNote object and Content. Although the ContentDocumentLink and Related Record entities are not put on the Content Object Model page, but they are there.

3
  • I must be doing something wrong here. I'm still just pulling my user ID. That ContentNote and Content flow is very helpful. I'm still stuck (for now) but thank you! May 21 '20 at 16:03
  • 1
    When you upload a file into the Files/Notes & Attachment Related List, there should be two records of ContentDocumentLink created, one linked to User and another to the parent record. You can try click on your newly uploaded file, on the top of the preview page, choose "View File Details" and it would bring you to the ContentDocument record, and on default layout, you should be able to see the "Share With" related list, that is the ContentDocumentLink records.Click on the "Share With" and see the URL May 21 '20 at 16:27
  • Thank you Hengky. I still have to run more examples but this seems to be what I wasn't comprehending. I just enabled the Salesforce Files setting: Files uploaded to the Attachments related list on records are uploaded as Salesforce Files, not as attachments. May 21 '20 at 16:33
2

As @Hengky Ilawan said, there's a junction object that contains the parent's Id and the ContentDocumentId.

You can retrieve your ParentId using this query:

SELECT LinkEntityId FROM ContentDocumentLink WHERE ContentDocumentId = 'yourContentDocId'
1
  • Thank you for the quick response. LinkedEntityId is showing my User ID, not the Opportunity record it resides in. Does it matter if I added these records via Page Layout into Files and didn't use a Visualforce upload page to insert on the backend? Without the Opp Id, I'm pretty stuck here. May 21 '20 at 16:00

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.