Last active
July 6, 2020 04:54
-
-
Save ankushsomani09/82bbb9d60a0032c00e630e8f417e2fb1 to your computer and use it in GitHub Desktop.
Find Active, Inactive and Total users per Role-vise across salesforce Org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Find use of Role across active/inactive users | |
List < User > lstUsers = [Select Id, IsActive, ProfileId, UserRoleId from user where UserRoleId != null]; | |
map < String, Integer > mapGroupToInActive = new Map < String, Integer > (); | |
map < String, Integer > mapGroupTotal = new Map < String, Integer > (); | |
for (User objUser: lstUsers) { | |
if (!objUser.IsActive) { | |
if (mapGroupToInActive.containsKey(objUser.UserRoleId)) | |
mapGroupToInActive.put(objUser.UserRoleId, mapGroupToInActive.get(objUser.UserRoleId) + 1); | |
else | |
mapGroupToInActive.put(objUser.UserRoleId, 1); | |
} | |
if (mapGroupTotal.containsKey(objUser.UserRoleId)) | |
mapGroupTotal.put(objUser.UserRoleId, mapGroupTotal.get(objUser.UserRoleId) + 1); | |
else | |
mapGroupTotal.put(objUser.UserRoleId, 1); | |
} | |
String csvHeader = 'RoleId total inactive \n'; | |
List < String > csvRows = new List < String > (); | |
for (String str: mapGroupTotal.keyset()) { | |
csvRows.add(str + ' ' + mapGroupTotal.get(str) + ' ' + mapGroupToInActive.get(str)); | |
} | |
String CsvFiletotal = csvHeader + String.join(csvRows, '\n'); | |
system.debug(':::::::'); | |
system.debug(CsvFiletotal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment