Is it possible to map ContentDocumentLink (LinkedEntityId field) to a custom object record? As per the doc Documentation for LinkedEntityId, it has not been mentioned to be possible to reference a custom object, but I can see many standard objects. If it is not possible: Do we have any alternative solution to map a ContentDocument to a custom object in Salesforce?

2 Answers 2


Yes, you can relate documents to custom objects. Here's the code I used to determine that:

for(sobjecttype relatedTo: ContentDocumentLink.LinkedEntityId.getDescribe().getReferenceTo()) {
    if(relatedTo.getDescribe().isCustom()) {

You should see your custom objects listed in the debug logs.


The documentation does mention (though a little off-handedly) that custom objects can be set for LinkedEntityId, emphasis mine.


ID of the linked object. Can include Chatter users, groups, records (any that support Chatter feed tracking including custom objects), and Salesforce CRM Content libraries.

There are also several other mentions of "custom object" in the information for the "Visibility" field, which would be an odd thing to include if ContentDocumentLink couldn't link to custom SObjects.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .