+ Start a Discussion

ContentDocumentLink trigger

Hi, I need to some validation on ContentDocumentLink but triggers are not allowed on that object. Does anyone know I good way to add trigger-like behavior (check the data before insert/update, throw an error if data invalid) without actually having a trigger ? Thank you



Using the apex you can achive this.
firstly you need understand the links between these object - ContentWorkspace, ContentWorkspacedoc, ContentDocument, and Contentversion

Now In apex, write a code for insert contentversion( contentversion is file that you will upload).
Contenworkspace is the Library.
Contentworkspacedoc, is the object that provides links between contentversion(contentdocument) and contentworkspace

ContentWorkspaceDoc cwdoc = new ContentWorkspaceDoc();
cwdoc.ContentDocumentId = cv.ContentDocumentId; //contentversio's ContentDocumentId.
cwdoc.ContentWorkspaceId = cws.id; // contentworkspace id
insert cwdoc;

Content pack operations involving the ContentVersion object, including slides and slide autorevision, don't invoke triggers.

Content packs are revised when a slide inside of the pack is revised.

Values for the TagCsv and VersionData fields are only available in triggers if the request to create or update ContentVersion records originates from the API.

You can't use before or after delete triggers with the ContentVersion object.

For details please refer: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_ignoring_operations.htm