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
Hanna BergsmaHanna Bergsma 

Trigger to update owner of content version to related Case field

Is there a way to set the ownerId = Content version> email> Case>Last Modified By?

I want to set the owner of the file to whoever has been working the case. These files are created via email-to-case. Please help with actual suggestions, not links. I have been reading blogs for days and nothing has worked. I'm at wits end on how to allow my users to delete Files on emails.

trigger ConDoc on ContentVersion (after insert) {

    List<ContentVersion> conver = [SELECT Id, Title, OwnerId FROM ContentVersion WHERE Id IN: Trigger.newMap.keySet()];

    for (ContentVersion CV: conver){
        CV.OwnerId= '3D00GF0000007fwJR';
        CV.Title = 'HannaTest';
    }

    update conver;

}
Abhishek BansalAbhishek Bansal
Hi Hanna,

Are you getting any issues with this code? Can we connect to discuss the issue and find out a solution for this?

Thanks,
Abhishek Bansal.
Email: abhibansal2790@gmail.com
Skype: abhishek.bansal2790
Hanna BergsmaHanna Bergsma
Hello,

It seems to be working fine, I just want to have the case owner's ID instead of hard coding an ID in Owner.id field. The file is an attachment to an email that came in via email-to-case