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
AladinCGAladinCG 

How to cover trigger on sObject ContentDocument?

Hi,
I have created trigger on the sObject ContentDocument (before delete) and contentVersion (before insert, after insert). We want to create test class for these triggers. While inserting ContentVersion we are getting 'FIELD_CUSTOM_VALIDATION_EXCEPTION' error. For contentDocument we have tried to fetch exising ContentDocument using SOQL and tried to delete it, but it does't work. Please help me to write correct test method for contentVersion and ContentDocument.
Thanks
Best Answer chosen by AladinCG
Sagarika RoutSagarika Rout
First thing is the error is completely related to  validation exception , if it is not the contentVersion , may be it is related to some other object based on your trigger code.
and secondly testclass is nothing but just it will verify your code and cover it .
While inserting record through testclass , the trigger will fire and execute, verify your trigger completely , you will come to know from where you get the exception,

All Answers

Sagarika RoutSagarika Rout
Hi Nirav ,

          I think you have written any custom validation rule on ContentVersion , and while inserting data through test class ,
    you are not following those validation , that is the reason , you are getting exception .
    To avoid this , you can enter the data in such way that will not hit the validation or else you can deactivate validation rule , so you will not get any exception while running test class.

Regards
Sagarika
AladinCGAladinCG
Hey Sagarika

Thanks for replaying, but I havent written any custom validation rule on ContentVersion

Thanks

Sagarika RoutSagarika Rout
First thing is the error is completely related to  validation exception , if it is not the contentVersion , may be it is related to some other object based on your trigger code.
and secondly testclass is nothing but just it will verify your code and cover it .
While inserting record through testclass , the trigger will fire and execute, verify your trigger completely , you will come to know from where you get the exception,
This was selected as the best answer