Thursday, October 18, 2018

What happen on Content Document Link if we upload Salesforce Files from record?

This entry specifically to know more about ContentDocumentLink which are not represented in diagram below.I happen to know more about this object after I experimenting on content's trigger(in future post).

To understand how the content relationship works please refer to diagram below .
 content objects diagram version 44.
refer to Salesforce for latest diagram

The highlight of this article is to identify ContentDocumentLink object that not appear in the diagram above.

ContentDocumentLink is Represents the link between a Salesforce CRM Content document or Salesforce file and where it's shared.
Field LabelAPI Field NameTypeLengthPrecisionScale
ContentDocumentLink IDIdid15
DocumentContentDocumentIdreference15
Is DeletedIsDeletedboolean
Linked EntityLinkedEntityIdreference15
Share TypeShareTypepicklist40
System ModstampSystemModstampdatetime
VisibilityVisibilitypicklist40
Experiment : Upload a file from Opportunity record.Once upload, click on the file and copy the id in URL. The id is represent contentdocumentid.Open Developer Console --> Execute Anonymous. Paste this code with contentdocumentid that you got.


1
2
3
system.debug('@@@ ContentVersion :  '+new List<ContentVersion> ([select Id ,ContentDocumentId from ContentVersion where ContentDocumentId ='06990000005Eor5']).size());
system.debug('@@@ ContentDocument :  '+new List<ContentDocument> ([select Id  from ContentDocument where Id ='06990000005Eor5']).size());
system.debug('@@@ ContentDocumentLink :  '+new List<ContentDocumentLink> ([select Id ,ContentDocumentId from ContentDocumentLink where ContentDocumentId ='06990000005Eor5']).size());

The result is like below, notice that we have two contentdocumentlink records.

To check what actually record being inserted in ContentDocumentLink, please run SOQL below:
select Id, ContentDocumentId, LinkedEntityId, IsDeleted, LinkedEntity.Type from ContentDocumentLink where ContentDocumentId ='06990000005Eor5' 
Result - LinkedEntity.Type are User (who upload the File) and Opportunity (the record where the file is uploaded)

Hope this will give you clear picture on what ContentDocumentLink object is doing.I am doing testing and find something interesting on content object which I will share with you later.

Happy coding

No comments:

Post a Comment