Skip to content

Instantly share code, notes, and snippets.

@thepaulfox
Created June 24, 2015 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thepaulfox/3f525d0c5f9856d5ca50 to your computer and use it in GitHub Desktop.
Save thepaulfox/3f525d0c5f9856d5ca50 to your computer and use it in GitHub Desktop.
Why won't ContentDocument Trigger Fire
trigger ContentDocumentTrigger on ContentDocument (before delete){
System.Debug('Trigger Fired');
}
Id MyId = '[fill this in]' // Use some record that has feed items enabled
FeedItem myPost = new FeedItem(ParentId = MyId
, ContentData = Blob.valueOf('anImage')
, ContentFileName = 'testFeedItem.jpg');
insert myPost;
myPost = [SELECT RelatedRecordId
FROM FeedItem
WHERE Id = :myPost.Id];
System.Debug(myPost.RelatedRecordId);
ContentDocument doc = [SELECT Id FROM ContentDocument WHERE Id = :myPost.RelatedRecordId];
delete doc; // Comment this out when you want to test via UI
@thepaulfox
Copy link
Author

If you save the trigger into your org and then run the execute anonymous code then you'll see that the trigger never fires.

However, if you comment out line 11 of the execute anonymous code then you can get the doc id and delete it through the UI. THEN the trigger will show up in the debug logs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment