2

Customer is using Email2Case, configured to store email attachments as Files (Content Document/Version/Link). They specifically will allow agents to delete these files, as they get many unneeded attachments (logo images, etc). However, they would like to have a record when something is deleted. Is there any way to configure Case Feed (or History Tracking) to record when a linked File is deleted?

If not with config, could I do it in code? I could trigger on delete of the ContentDocumentLink to know the file was removed from the case, but what would I create/insert to show the deletion in the feed?

2

You can write trigger on ContentDocument in which you need to get reference to ContentDocumentLink as it will have the information - with which objects that document has been shared with. Using the links, you can post the feed - using object FeedItem.

trigger ContentDocTrigger on ContentDocument (before delete) {

    if(Trigger.operationType==System.TriggerOperation.BEFORE_DELETE) {
        List<ContentDocumentLink> links = [SELECT Id, LinkedEntityId, ContentDocumentId, ContentDocument.Title 
                                           FROM ContentDocumentLink
                                           WHERE ContentDocumentId=:Trigger.oldMap.keySet()];
        System.debug('links => '+links);
        List<FeedItem> feeds = new List<FeedItem>();
        for(ContentDocumentLink cdl : links) {
            if(cdl.LinkedEntityId.getSObjectType()==Case.SObjectType) {
                feeds.add(new FeedItem(
                    ParentId=cdl.LinkedEntityId,
                    Type='TextPost',
                    Body='File: <b>'+cdl.ContentDocument.Title+'</b> has been deleted',
                    isRichText=true
                ));
            }
        }
        System.debug('feeds => '+feeds);
        if(feeds.size()>0) insert feeds;
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.