You need to sign in to do that
Don't have an account?
Apex developer 21
Need some help on how to insert ContentDocumentLink in the correct way
@istest public class TestNoteOnContentDocuments { static testmethod void NoteOnContentDoc(){ ContentVersion contentVersion = new ContentVersion( Title = 'Penguins', PathOnClient = 'Penguins.jpg', VersionData = Blob.valueOf('Test Content'), IsMajorVersion = true ); insert contentVersion; List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument]; ContentDocumentLink link=new ContentDocumentLink(); link.LinkedEntityId=ContentDocumentLink.id; link.contentdocumentid=[select contentdocumentid from contentversion where id =: ContentDocument.id].contentdocumentid; link.ShareType = 'A'; insert link; DmlException expectedException; Test.startTest(); try { delete documents; } catch (DmlException dmx) { Boolean expectedExceptionThrown = dmx.getMessage().contains('Approval pending. You do not have the permission to edit/delete this note/attachment, please contact your administrator.') ? true : false; System.assertEquals(expectedExceptionThrown, true); } Test.stopTest(); } }
You can refer this test class Thank you
1. seealldata=true is a very bad practice of writing test classes.
2. The setup of test data is not proper
3. No asserts present