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
sfdcdudesfdcdude 

Trigger on content document

Hi Team,

I have added notes and attachments to custom object__c. when user deletes a file from content document object or content document link object, I need to throw an error to user. Please post code if you have handy.

Thanks.
sfdcdudesfdcdude
Hi Charudutt,

The above code is not working and i tried with below one, and in debug it is showing parent ID value as null. Please crct if i did something wrong.

public static void restrictDeleteFiles(list<ContentDocument> oldlistContentDocument) {
        
        for (ContentDocument cd : oldlistContentDocument ) {
            system.Debug('parent id is----'+cd.ParentId);
                if(cd.ParentId.getSObjectType().getDescribe().getName() == 'custom_object__c'){
                    cd.adderror('You Cannot delete a record once uploaded.');
}
            
        }
    }