title: "Related Content" stored in which object / How to create "Related Content" records from Apex
body: <p>If you navigate to account/contact/custom object we do have a related list "related content" (if content is enabled and related list is added to page layout).  </p>
  
  <p>My question is were are these "related content" records stored? in which object?</p>
  
  <p>Using apex I'm able to upload file to content version, but not able to create or find the object which stores the "related content" information.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Tried to create a link to show up in "related content" section of account, but no success. Got error " Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, You cannot create a link for this type of entity through the api: [LinkedEntityId]"</p>
  
  <p>Any idea?</p>
  
  <pre><code>           ContentVersion cv = new ContentVersion(
              versionData = EncodingUtil.Base64Decode(base64BlobValue),
              Title = fileName,
              PathOnClient = '/'+fileName,
              FirstPublishLocationId = '058900000009KcL'
          );
          insert cv;
  
          //fetch ContentDocumentId
          cv = [Select Id,ContentDocumentId from ContentVersion where Id = :cv.Id];
  
          insert new ContentDocumentLink(LinkedEntityId=parentId,ContentDocumentId=cv.ContentDocumentId,ShareType='V');
  </code></pre>
  
  <p>** USE CASE **</p>
  
  <p>The use case is to allow user to attach content right from object detail page for eg say Account will have button say Attach Content, this will bring upload content page, once uploaded (i will create contentversion records - this is happening perfectly, no errors) and then I need to relate the uploaded content to account (from which request orginated) ie create "related content" records (here I'm facing difficulty, trying to create contentdocumentlink records but its erroring out).</p>
  
  <p>The use case is just one click to attach content to account or opportunity instead of long current process were user goes to content, uploads there first and then comes back to account/opty and searches content again, and then attaches it to account/contact.</p>