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
Lam CorporationLam Corporation 

Prevent Chatter File being deleted from the "Files" related list on Account

Hi all,

I am trying to prevent the deletion with a trigger for Chatter Files from the "Files" related list on Account. 
It seems to work on the Files tab but not the related list on the Account.
I have tried using the ContentVersion object, also the ContentDocument. Nothing is working.
Can anyone help? Many thanks

trigger FilePreventDelete on ContentDocument (after delete) {

    for (ContentDocument record : trigger.old)
    {
        if (record.Id != '')
        {
            record.addError('You can not delete a File once uploaded');
        }
    }
}
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Lam,

Please check the below link for reference.
https://success.salesforce.com/ideaView?id=08730000000Br7fAAC

Happy to help.

Best Regards
Rahul Kumar
Lam CorporationLam Corporation
Hi, Thanks but I've seen the idea that you have posted before. I believe it is referring to a declarative solution to disallow Files to be deleted using Profiles. I understand this can not be done with declarative so I am looking for a code solution.

Does any have any other experience or ideas? thanks