Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.');
- }
- }
- }
- @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.'));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement