Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. trigger NoteOnContentDocument on ContentDocument (before delete) {
  2. for (ContentDocument c : Trigger.old){
  3. List<ContentDocumentLink> links = [SELECT LinkedEntityId FROM ContentDocumentLink
  4. WHERE ContentDocumentId= :c.Id];
  5. if (!links.isEmpty() && Approval.isLocked(links.get(0).LinkedEntityId)){
  6. c.addError('Approval pending. You do not have the permission to edit/delete this note/attachment, please contact your administrator.');
  7. }
  8. }
  9. }
  10.  
  11. @istest
  12. public class TestNoteOnContentDocuments {
  13. static testmethod void NoteOnContentDoc(){
  14. ContentVersion contentVersion = new ContentVersion(
  15. Title = 'Penguins',
  16. PathOnClient = 'Penguins.jpg',
  17. VersionData = Blob.valueOf('Test Content'),
  18. IsMajorVersion = true
  19. );
  20. insert contentVersion;
  21. List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
  22. delete documents;
  23.  
  24. DmlException expectedException;
  25. Test.startTest();
  26. try { delete documents; }
  27. catch (DmlException dmx) {
  28.  
  29. 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;
  30. System.assertEquals(expectedExceptionThrown, true);
  31. }
  32. Test.stopTest();
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement