Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 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, 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. try{delete documents[0];
  23. system.assert(true);
  24. }
  25. catch(DmlException e){
  26. System.Assert(e.getMessage().contains('Approval pending. You do not have the permission to edit/delete this note, please contact your administrator.'));
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement