I have the following trigger which gives a red flag in the development console on the addError
line, how do i remove this with the unittest?
Trigger
trigger NoteOnContentDocument on ContentDocument (before delete) {
for (ContentDocument c : Trigger.old){
List<ContentDocumentLink> links = [SELECT LinkedEntityId FROM ContentDocumentLink
WHERE ContentDocumentId= :c.Id];
if (!links.isEmpty() && Approval.isLocked(links.get(0).LinkedEntityId)){
c.addError('Approval pending. You do not have the permission to edit/delete this note, please contact your administrator.');
}
}
}
Test Class
@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];
try{delete documents[0];
system.assert(true);
}
catch(DmlException e){
System.Assert(e.getMessage().contains('Approval pending. You do not have the permission to edit/delete this note, please contact your administrator.'));
}
}
}
links
to be not empty...and for the linked entity to be locked. Neither of those seem to be the case. Your assertion pattern on thetry
/catch
also needs an overhaul. At least changesystem.assert(true)
tosystem.assert(false)
.