I'm trying to write a trigger on ContentDocument to align file access rights to the different user. I can align file access rights to the user when I upload a new version of the file. But to align the rights after I have uploaded a new file, the afterInsert trigger is not fired. Is there no afterInsert trigger on ContentDocument and do you know another way to implement that?

  • 1
    I believe you should be writing the trigger on ContentVersion object, not the ContentDocument object – Chris Duncombe Sep 10 '13 at 13:53

There is 3 things I would mention to you about the ContentDocument Object and ContentVersion Object.

1. ContentDocument object only supports delete(), describeSObjects(), query(), retrieve(), undelete(), update() calls.

  • A user can change ownership of a Salesforce CRM Content document or Chatter file if any of the following are true: The user is the current owner, or has either the “Modify All Data” or "Manage Salesforce CRM Content” permission enabled. The user has the “Manage Library” permission enabled for the library containing the document.

  • Documentation can be found here: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_contentdocument.htm

2. ContentVersion Object supports create(), describeLayout(), describeSObjects(), query(), retrieve(), search(), update(), upsert() calls.

3. Both the objects have the ownerId field with the following properties: Create, Group, Sort, Update.

Try writing the after insert trigger on the ContentVersion object.

Hope this was helpful.


trigger ContentVersion_OnAfterInsert on ContentVersion (After Insert) {
     //Write the logic
  • Hi subodhbahl, this answer does explain that ContentVersion should be used, but simply quoting documentation isn't all the best: providing an example would be even better! – Matt Lacey Sep 10 '13 at 23:34
  • @LaceySnr I understand that. The trigger is already written on ContentDocument object, try replacing the object name to ContentVersion and it should work. I don't think I should be writing a whole trigger for that. I specifically mentioned the ownerId field in my answer for the user to understand what I mean. – subodhbahl Sep 10 '13 at 23:37
  • 1
    I wasn't saying you have to, just that the answer was flagged by a user and down voted because it didn't provide an example. Generally the more effort in the more votes you get :) – Matt Lacey Sep 10 '13 at 23:39
  • 1
    Aight, time to edit the answer. Thanks Matt! Hope the leg is better now ;) – subodhbahl Sep 10 '13 at 23:41

The trigger on ContentVersion object didn't work, so I writed a trigger on FeedItem object and it works.

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.