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
levaleva 

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
Vinita_SFDCVinita_SFDC

Hello,

 


Using the apex you can achive this.
firstly you need understand the links between these object - ContentWorkspace, ContentWorkspacedoc, ContentDocument, and Contentversion
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_content.htm#sforce_api_erd_co...

Now In apex, write a code for insert contentversion( contentversion is file that you will upload).
then,
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