Snippets

Mike Chale ContentDocumentLink Trigger & Test

Created by Mike Chale
1
2
3
4
5
trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert) {
    for(ContentDocumentLink l:Trigger.new) {
        l.Visibility='AllUsers';
    }
}
@isTest
private class ContentDocumentLinkTriggerTest {
    @isTest
    static void ContentDocumentLinkSharedToAllUsers(){
        Account testRecord = new Account(Name = 'Test');
        insert testRecord;
        ContentNote testNote = new ContentNote(Title = 'Test Note');
        insert testNote;
        
        ContentDocumentLink link = new ContentDocumentLink();
        link.LinkedEntityId = testRecord.Id;
        link.ContentDocumentId = testNote.id;
        link.ShareType = 'I';
        link.Visibility = 'SharedUsers';
        
        Test.startTest();
        insert link;
        Test.stopTest();
        
        link = [SELECT Id, Visibility FROM ContentDocumentLink WHERE Id = :link.Id];
        System.assertEquals('AllUsers', link.Visibility);
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.