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

Testing before triggers on a Content record manual insert with required custom fields?


I have a required custom field which is also used to fire associated triggers. As long as the document isn't associated with a workspace, the field doesn't exist.


The problem I'm having is that when I emulate the manual insert, all of the custom field processes have to happen in an update. But when I insert a ContentWorkspaceDoc in my test for the just-inserted document, all the custom fields suddenly become live as a result of associating it with a Workspace. As the required field doesn't have a value, the ContentWorkspaceDoc insert fails because the associated ContentVersion record update fails without the required field. .


So, in my test methods:

1) I can't add a required custom field value into a ContentVersion record unless it is associated with Workspace via the insertion of a ContentWorkspaceDoc, and

2) I can't insert a ContentWorkspaceDoc for a ContentVersion record unless the required custom field has a value.


The triggers are working in practice. The updates are occuring as expected based on the trigger.old required field being null ( as it didn't exist on the record when it was first inserted without a workspace reference) during the before update phase.


Seems weird to not be able to test the triggers written for the Content object, even though those triggers are working in practice. Anybody know how to do this??