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

Relating Content to A Custom object in APEX



My stuck with this feature:


I need to Relate (Connect) a ContentVersion object (A file I retrive from an email) I create in my Apex code to a custom object I have in the database.


The GUI feature that allows to do that has a Related To lookup filed but I can't find how to do this in APEX.


I appricate an advise







Not Clear with your requirement.

can you please explain in detail


Let me try and explain:


I have an APEX class which processes an incoming email message.

The code should take the attachment to the email, create a ContentVersion object and relate this Content to another custom object I have lets say AAA

I was able to achieve everything but relating the Content to AAA.


This functionality is available when adding a Content from the Detail Page GUI of AAA.


How do I do this in my APEX code.




Hi Kruvi,


Where you able to find a workaround for this? I'm facing the same issue. Here's a link to my case: