0

I am completely lost on how to populate a ParentID for Content Documents. I would like to find the parent record (custom object record) linked to the Content Document. I have easily sorted it in the Attachment Object, but having issues with the Content Documents. Grateful for your help.

Finally, I used dataloader.io to try to pull the content document data, as well as Power BI. I saw codes on queries to conduct, but not sure where users input these queries to pull the data needed. Looking forward to your help. #Salesforce #ParentID #Query #SOQL #PowerBI #ContentDocument #ContentDocumentLink #LinkedEntityID

2 Answers 2

0

For content document there is another object called ContentDocumentlink where you will get the object reference for which it is related to .

In ContentDocumentLink we have ContentDocumentid and LinkedEntityid which will give you an overview of which contentdocument to related to object.

As per the object reference of ContentDocument ParentId in ContentDocument object is ID of the library that owns the document. Created automatically when inserting a ContentVersion via the API for the first time.

0

Check this code for your reference

ContentNote contentNote = new ContentNote();
contentNote.Title       = 'First Note';

// You can pass html type text here for rich text formatted text
String body             = '<b>This is my first note</b>';     
contentNote.Content     = Blob.valueOf(body);
insert contentNote;

ContentDocumentLink link = new ContentDocumentLink();
link.ContentDocumentId   = contentNote.id;
link.LinkedEntityId      = '001J2000009E7XD';
link.ShareType           = 'I'; 
link.Visibility          = 'AllUsers'; 
insert link;

Basically in ContentNote record you specify the enhanced note content that you want to add. Here you can specify title and the rich text formatted body of that enhanced note.

Since a single record can have multiple enhanced notes and also a single note can be related to multiple records by sharing, a junction object named ContentDocumentLink exist between the two to establish this many to many relation.

Here in LinkEntityId field you specify the record Id for which you want to create the enhanced note. Visibility field determines who all can have access to this note and ShareType determines what access they will have on this note

Visibity field can have below values enter image description here

And shareType can have below values. enter image description here

Here one thing you may notice is though ContentDocumentId is a lookup to ContentDocument Object, providing contentNote Id still works and doesnt causes error .Basically right after contentNote record is created, Salesforce creates contentDocument record in background with Id same as this contentNote record

You can check this by running this query

Select Id,Description,FileExtension,FileType,SharingPrivacy,Title from ContentDocument where Id =: contentNote.Id

Since both have same Id value you dont need to explicitly query contentDocument record and instead can directly provide contentNote Id.

You must log in to answer this question.

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