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
Josh SummittJosh Summitt 

How do i trigger an event when a Document is uploaded

Hello,
I need to run some operations when a file is uploaded via the Document tab. On other pages this is easy because i can trigger on Attachment or FeedItem, etc. I don't see a way to trigger when a file is being uploaded from Documents.

FYI i'm looking for someing like

trigger checkFile on Document(before insert){

}
Since document does not have a trigger function how can i check this before its completely uploaded to the database. I want to return an error if its not correct and prevent the file from being uploaded.

bob_buzzardbob_buzzard
Documents don't support triggers I'm afraid, so there's not very much you can do to influence the behaviour.  Attachments and content files do, so if you can use those sobjects you'll be able to add the functionality that you are looking for.
Josh SummittJosh Summitt
So is the solution to disable this functionality for user's so they cannot bypass our checks.
bob_buzzardbob_buzzard
I really couldn't say whether that is the correct solution for you I'm afraid.  If you have to have those checks in place before users can save a document, then maybe so.  
Josh SummittJosh Summitt
Is there any chance that triggers will be enabled on future versions of the API? Is there anyway to override the Document to enable this feature?
bob_buzzardbob_buzzard
There's always a chance, but I haven't heard anything of this nature.  There isn't an idea on the idea exchange for this, so you could create one and see if it gets any traction.  My personal view is that it is unlikely as documents are pretty old functionality, but what do I know.

There's no way to override the Documents functionality - they aren't first class sobjects so you don't get visualforce overrides and the like.
Alex TMAlex TM
I appreciate this is a very old thread, but Change Data Capture can do this now :)