2

Maybe someone knows how to attach ContentDocument to record through Apex? I need to copy ContentDocuments (which are in Google Doc's, Notes and Attachments related list) from one Object to another. I tried to insert ContentDocument and AttachedContentDocument but we can't do insert operation on these objects. I can insert ContentVersion but don't know is there a way to attach it to record?

I will appreciate any kind of help.

  • Is your existing data in attachment ?And you just want to re parent ?or totally move to content version ? – Mohith Shrivastava Jan 30 '16 at 21:38
  • ContentVersion may be associated to an sobject via custom lookup fields – cropredy Jan 30 '16 at 21:58
  • There is a content document link object you can use to connect content doc or content version w specific record, can't recall the specifics but was working on that a few months back. – gorav Feb 1 '16 at 0:50
  • See developer.salesforce.com/docs/atlas.en-us.api.meta/api/… for details on content document link object. For some unknown reason I have only been able to set shareType to V (for viewer). All other values throw a restricted picklist error. – gorav Feb 1 '16 at 23:57
  • That is right, you can attach ContentDocument with ContentDocumentLink object. Thanks to all of you guys. – V. Ber Feb 2 '16 at 5:23