Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @AuraEnabled
- public static String getCurrentShares(final Id recordId) {
- if (!hasEdit(recordId)){
- throw new AuraHandledException('Only the record owner or administrators can access permissions');
- }
- List<SObject> results = Database.query(buildQuery(recordId));
- List<ShareWrapper> output = new List<ShareWrapper>();
- Set<Id> groupAndUserIDs = new Set<Id>();
- for (SObject so : results) {
- ShareWrapper sh = new ShareWrapper();
- sh.RowCause = String.valueOf(so.get('RowCause'));
- sh.AccessLevel = String.valueOf(so.get(getAccessLevelField(objectTypeFromId(recordId))));
- sh.UserOrGroupId = (Id)so.get('UserOrGroupId');
- groupAndUserIDs.add(sh.UserOrGroupId);
- output.add(sh);
- }
- Map<Id, User> userMap = new Map<Id, User>([SELECT Name FROM User WHERE Id IN :groupAndUserIDs]);
- Map<Id, Group> groupMap = new Map<Id, group>([SELECT Name FROM Group WHERE Id IN :groupAndUserIDs]);
- for (ShareWrapper sh : output) {
- if (userMap.get(sh.UserOrGroupId) != null) {
- sh.UserOrGroupType = 'User';
- sh.UserOrGroupName = userMap.get(sh.UserOrGroupId).Name;
- } else if (groupMap.get(sh.UserOrGroupID) != null){
- sh.UserOrGroupType = 'Group';
- sh.UserOrGroupName = groupMap.get(sh.UserOrGroupId).Name;
- }
- }
- return JSON.serialize(output);
- }
- SharingComponentController.getCurrentShares(acc.id);
- }catch(AuraHandledException e) {
- System.debug(e.getMessage());
- System.assert(e.getMessage().contains('My Error Message'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement