Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. @AuraEnabled
  2. public static String getCurrentShares(final Id recordId) {
  3. if (!hasEdit(recordId)){
  4. throw new AuraHandledException('Only the record owner or administrators can access permissions');
  5. }
  6.  
  7. List<SObject> results = Database.query(buildQuery(recordId));
  8. List<ShareWrapper> output = new List<ShareWrapper>();
  9.  
  10. Set<Id> groupAndUserIDs = new Set<Id>();
  11.  
  12. for (SObject so : results) {
  13. ShareWrapper sh = new ShareWrapper();
  14. sh.RowCause = String.valueOf(so.get('RowCause'));
  15. sh.AccessLevel = String.valueOf(so.get(getAccessLevelField(objectTypeFromId(recordId))));
  16. sh.UserOrGroupId = (Id)so.get('UserOrGroupId');
  17. groupAndUserIDs.add(sh.UserOrGroupId);
  18. output.add(sh);
  19. }
  20.  
  21. Map<Id, User> userMap = new Map<Id, User>([SELECT Name FROM User WHERE Id IN :groupAndUserIDs]);
  22. Map<Id, Group> groupMap = new Map<Id, group>([SELECT Name FROM Group WHERE Id IN :groupAndUserIDs]);
  23.  
  24. for (ShareWrapper sh : output) {
  25. if (userMap.get(sh.UserOrGroupId) != null) {
  26. sh.UserOrGroupType = 'User';
  27. sh.UserOrGroupName = userMap.get(sh.UserOrGroupId).Name;
  28. } else if (groupMap.get(sh.UserOrGroupID) != null){
  29. sh.UserOrGroupType = 'Group';
  30. sh.UserOrGroupName = groupMap.get(sh.UserOrGroupId).Name;
  31. }
  32. }
  33.  
  34.  
  35. return JSON.serialize(output);
  36. }
  37.  
  38. SharingComponentController.getCurrentShares(acc.id);
  39. }catch(AuraHandledException e) {
  40. System.debug(e.getMessage());
  41.  
  42. System.assert(e.getMessage().contains('My Error Message'));
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement