function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
James GJames G 

ContentDocumentLink Issue

I may be missing the point here but I am trying to link a new document created in a Content Library using ContentVersion.  That works like a champ and I am placing the document in the correct Library folder and have permissons for the folder wide open a this point.  What I need to do is show a link to the newly created document  directly from within the Custom Object's related lists section.  I have already dragged the Related Content list section into the page layout and it gives me 3 buttons (Find Content, Search All, & Deliver Content) and I can attach the new doc this way but cannot for the life of me figure out to do this programmaticzlly using APEX. Any clues?  Anybody?  Thanks in advance!

Raj.ax1558Raj.ax1558

Yes, Using the apex you can achive this.

firstly you need understand the links between these object - ContentWorkspace, ContentWorkspacedoc, ContentDocument, and Contentversion

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_content.htm#sforce_api_erd_content

 

Now In apex, write a code for insert contentversion( contentversion is file that you will upload).

then,

Contenworkspace is the Library. 

Contentworkspacedoc, is the object that provides links between contentversion(contentdocument) and contentworkspace

 

 ContentWorkspaceDoc cwdoc = new ContentWorkspaceDoc();
                cwdoc.ContentDocumentId = cv.ContentDocumentId; //contentversio's ContentDocumentId.
                cwdoc.ContentWorkspaceId = cws.id; // contentworkspace id
insert cwdoc;


Please mark this as solution for others to get it easily