Below is the test class that I have written for contentdocumentlink trigger. And its failing to insert the cdl due to insufficent access.
@IsTest
public class TestAttachmentHandler
{
static testMethod void validateHelloWorld()
{
Master_Rate_Deck_XRef__c availableRateDeck = new Master_Rate_Deck_XRef__c(Deck_Type__c = 'Wholesale', RateDeckType__c = 'Std.', Billing_Term_Rate_Type__c = 'LRN');
insert availableRateDeck;
Blob beforeblob=Blob.valueOf('Unit Test Attachment Body');
ContentVersion cv = new ContentVersion();
cv.title = 'test content trigger';
cv.PathOnClient ='test';
cv.VersionData =beforeblob;
insert cv;
ContentVersion testContent = [SELECT id, ContentDocumentId FROM ContentVersion where Id = :cv.Id];
ContentDocumentLink contentlink=new ContentDocumentLink();
contentlink.LinkedEntityId=availableRateDeck.id;
contentlink.ShareType= 'C';
contentlink.LinkedEntityId = availableRateDeck.Id;
contentlink.ContentDocumentId=testcontent.ContentDocumentId;
contentlink.Visibility = 'AllUsers';
insert contentlink
}
}
Error:System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_OR_READONLY, You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.: []