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
Dale WorthingtonDale Worthington 

Assistance writing a test class for ContentDocumentLink

Hi All
I have used the help on this board to create to apex triggers which impact the ContentDocumentLink and ContentDocument object. These triggers work great in the sandbox. When i go to deploy these triggers into production i get an error saying that i dont have the right code coverage.

I believe the way to fix this is to write a test class, i have tried to do this with little success. Is there a way i can get around the need for code coverage? Is there an easy way that someone with very rudimentary understanding of apex and write a trigger?

The triggers are:
trigger ContentDocumentLinkTrigger2 on ContentDocumentLink (before delete) {
    for (ContentDocumentLink cdl : Trigger.old) {
         if([SELECT PermissionsModifyAllData FROM Profile WHERE Id = :UserInfo.getProfileId()].PermissionsModifyAllData) {
        return;
    }
        cdl.addError('Document links cannot be removed');
    }
}
and
trigger ContentDocumentTrigger2 on ContentDocument (before delete) {
for(ContentDocument cd : Trigger.old){

    if([SELECT PermissionsModifyAllData FROM Profile WHERE Id = :UserInfo.getProfileId()].PermissionsModifyAllData) {
        return;
    }
        cd.adderror('Attached files cannot be deleted.');
    }
}