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
Sam Mohyee 8Sam Mohyee 8 

Unacknowledged bug: No trigger fires on Files uploaded through Chatter comments

I'm posting here in an effort to get what is clearly a gap/bug in functionality some attention. I tried the route of Salesforce support, but as always it was a frustrating weeks long process that ended with them suggesting I post an Idea to the IdeaExchange so it can remain unacknowledged for 3-5 years. 

Issue:  It is possible to upload a file to Chatter Files in a way that doesn't activate any triggers.

Ways to upload a file to chatter:
  1. 'Upload Files' link on the 'Files' tab
  2. Create a new Chatter post, using the 'File' post type
  3. Comment on an existing Chatter post, and use the 'Attach File' link

2 of these methods fire a trigger: 
  1. A trigger on ContentVersion will fire for uploads directly to the File Tab
  2. A trigger on FeedItem will fire if the file is uploaded on a File chatter post

However, it is possible to upload a file through a Chatter comment without firing any trigger!

Even if a trigger is in place on FeedItem, this trigger will only fire upon submitting the comment as a whole - it is possible to upload the attached file to a comment before the comment is even submitted!

Steps to replicate (upload to Files without firing a trigger):
1. Find a chatter post you can add a comment to.
2. Click the 'Attach File' link and select a file
3. An upload progress bar will complete - this is the point where a trigger should have fired!
4. Don't press the 'cancel' link on the attached file. So long as this isn't pressed, it doesn't matter whether the comment is actually posted or not.
5. Now go to your Files tab: voila, the comment's attached file was uploaded, even though the comment was never posted!

User-added image

Again, no trigger is fired on any object when a file is uploaded using this method. Clearly the file upload should not be allowed to complete until after the comment is posted, but this is not the case.

Am I going crazy here, or is this clearly unexpected behavior that needs to be fixed? Why am I having such a hard time trying to get Salesforce to acknowledge this is a real issue? 

 
Best Answer chosen by Andy Boettcher
Andy BoettcherAndy Boettcher
SalesforceDevs connected on Twitter here and is going to route the case appropriately internally.

All Answers

Andy BoettcherAndy Boettcher
Would you be willing to share the Case Number you logged with Salesforce?  Chasing functionality gaps like this is more about exposure than anything else.  Also, do log it as an Idea - even if it gets found and accelerated, don't "not do" any steps that Salesforce asks you to do.

Good troubleshooting, let me know of the Case Number and I can tweet it out to help visibility.
Sam Mohyee 8Sam Mohyee 8

Hi Andy, thanks for your help. The Case # is 12746736.

It's not that I don't plan on posting to the IdeaExchange, it's that I'm frustrated with that being the go-to solution for Salesforce Support, especially now that Salesforce has set up a 'Known Issues' section.

But perhaps you know something I don't: what exactly would be the benefit of posting to the IdeaExhange, when a functionality gap this obscure is unlikely to get the number of votes needed to even reach Salesforce's attention? Why are bugs and problems with existing functionality expected to compete in the same arena as new feature requests that will be far more popular? 

Andy BoettcherAndy Boettcher
I know it can be a bit frustrating - but we have to play the game.  I just tweeted this out on @salesforcedevs and #askforce, hopefully someone that can help us both out here will see it and offer up a path forward.

Thanks for logging and sharing!
thomastthomast

It seems like there are two separate, but related problems here:

  1. Clicking Attach File from a Comment, choosing "Upload a file from your computer", and then following through to clicking "Attach" immediately uploads the file as a Chatter File, in contrast to the UX for a File post, where the file isn't added to Chatter files until and unless the "Share" button is clicked.
  2. Neither that action of uploading a file through the Comment's Attach File link, or actually saving the Comment itself with the "Comment" button, fires any triggers. 
Additionally, it seems like ContentVersion triggers should always be fired when a new File is uploaded, regardless of the source. Do you agree?
Sam Mohyee 8Sam Mohyee 8

@thomast A correction to your #2 statement: when the comment itself is posted (via the 'Comment' button), a trigger on FeedItem is fired. But as you note, pressing the 'Comment' button doesn't affect whether or not the attached file is uploaded.

 

Aside from that, I do agree with you that ContentVersion triggers should fire for any File, regardless of the source!

Andy BoettcherAndy Boettcher
SalesforceDevs connected on Twitter here and is going to route the case appropriately internally.
This was selected as the best answer
Sam Mohyee 8Sam Mohyee 8
@Andy great, thanks for your help getting this in front of the right people!
Sanpreet SainiSanpreet Saini
Hi all, 

With due respect I do not think  that this is BUG it can also be WAD(working as Designed)

Below is the SAMPLE TRIGGER WHICH IS WOKING FINE. 

 
trigger PreventFileUpload on FeedComment (before insert) {
    
    for(feedcomment fd : trigger.new){
        if(fd.commenttype=='ContentComment'){
            fd.adderror('File upload not allowed through comments');
        }
        
        
    }

}

Regards, 
Sanpreet
Sam Mohyee 8Sam Mohyee 8
@Sanpreet, if you actually test your sample code you will see that your claim is incorrect.

Read the 'Steps to Replicate' section in my original post.. As I stated, the issue is NOT with preventing a feed comment. Rather, the issue is that the attachment to the feed comment is uploaded to Files regardless of whether the comment is posted or not, and no trigger is fired on the file. 
Ritesh Aswaney 8Ritesh Aswaney 8
If you're using the Lightning Experience UI - a trigger on ContentVersion can block all the channels via which files can be uploaded, be it FeedItem, FeedComment or Attachments.
Ashwath Kannan 14Ashwath Kannan 14
@Sam Mohyee - Where you able to find any workarounds or did salesforce acknowledge it as an known issue?
Sam Mohyee 8Sam Mohyee 8
@Ashwath

Salesforce has made no progress on this issue as far as I know. They created this idea to upvote: 
https://success.salesforce.com/ideaView?id=08730000000DoKpAAK

But, as Ritesh claims, apparently if you switch to Lightning Experience this will no longer be an issue. If only Lightning was a complete product and not a half-baked rollout!