[SalesForce] Trigger on ContentDocument

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?

Best Answer

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.

Code:

trigger ContentVersion_OnAfterInsert on ContentVersion (After Insert) {
     //Write the logic
}
Related Topic