daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public with sharing class DP_CL_SwitchDealership {
  2.     @AuraEnabled
  3.     public static User getUser(){
  4.         User thisUser = [select Id, Name from User where Id = :userInfo.getUserId()];
  5.         return thisUser;
  6.     }
  7.    
  8.     @AuraEnabled
  9.     public static List<Group> getAllGroups() {
  10.         List<Group> myGroups = new List<Group>();
  11.         myGroups = [SELECT Id, Name FROM Group WHERE (Type = 'Regular')];
  12.         return myGroups;        
  13.     }
  14.    
  15.     @AuraEnabled
  16.     public static List<Group> getGroupsOfUser() {
  17.         List<Group> myGroups = new List<Group>();
  18.         myGroups = [SELECT Id, Name FROM Group WHERE Id IN (SELECT GroupId FROM GroupMember WHERE UserOrGroupId = :userInfo.getUserId() AND UserOrGroupId != null)];
  19.         return myGroups;        
  20.     }
  21.    
  22.     @AuraEnabled
  23.     public static List<AccountContactRelation> getMyRelAccounts() {
  24.         List<AccountContactRelation> myAccounts = [SELECT AccountId, ContactId, Account.Name, Account.DP_Group_Id__c FROM AccountContactRelation WHERE Contact.DP_Related_User__c = :userInfo.getUserId()];
  25.         return myAccounts;
  26.     }
  27.    
  28.     @AuraEnabled
  29.     public static List<Group> doThisPublicGroupOnly(Id groupId) {
  30.         Group g = [SELECT Id, Name FROM Group WHERE Id = :groupId];
  31.         List<User> users = [SELECT Id, Name FROM User WHERE Id = :userInfo.getUserId()];
  32.        
  33.         //remove
  34.         List<GroupMember> listGroupMemberRemove = [SELECT Id FROM GroupMember WHERE (UserOrGroupID = :userInfo.getUserId())];
  35.         if(listGroupMemberRemove.size() > 0 ) {
  36.             delete listGroupMemberRemove;
  37.         }
  38.        
  39.         //add
  40.         List<GroupMember> listGroupMemberAdd = new List<GroupMember>();  
  41.         for (User u : users ) {
  42.             GroupMember gm = new GroupMember();
  43.             gm.GroupId = g.id;
  44.             gm.UserOrGroupId = u.id;
  45.             listGroupMemberAdd.add(gm);  
  46.         }
  47.         insert listGroupMemberAdd;
  48.        
  49.         List<Group> myGroups = new List<Group>();
  50.         myGroups = [SELECT Id, Name FROM Group WHERE Id IN (SELECT GroupId FROM GroupMember WHERE UserOrGroupId = :userInfo.getUserId() AND UserOrGroupId != null)];
  51.         return myGroups;
  52.     }
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top