In order to help HR manage license allocations for our HCM app, I worked up a proof of concept for a simple vf page that shows which users are assigned a specific permission set, and also are provisioned access to the HCM via a lookup to user on worker record.
I was able to get it working pretty quickly.
Now I want to add an additional function that will show which users have been given the permission set, but have not been 'granted access' yet via the lookup to user on the worker record.
Even though it seems like I should put this in a separate method, I tried just dumping the additional logic into the existing method to see what happens. Turns out that the debug logs are displaying the list of users I'm after, but the visualforce page does not display any values for the list PermSetOnly.
I started poking on moving this to a separate method, but I'm not sure on how to properly pass data between the first method and the second method, and how to minimize queries, since I've already done most of the work in the existing method.
And, I'm also very open to suggestions on how to improve any of this. Fortunately I'm an admin for my day job.
Code below
Controller
public class HCMLicensingController {
public integer ActiveUsersWithPermissions {get;set;}
public integer WorkersWithProvisionedUser {get;set;}
public list<user> PermSetOnly {get;set;}
public list<VANAHCM__Worker__c> getProvUsers(){
/*
* http://salesforce.stackexchange.com/questions/8910/how-can-i-efficiently-generate-a-setid-from-a-listsobject-structure
*/
//create set of user IDs for active users assigned the hcm employee perm set
list <PermissionSetAssignment> EmployeePermSet = new list<PermissionSetAssignment>([SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSetId = '0PS40000000P0pNGAS' AND AssigneeId IN (SELECT Id FROM User WHERE IsActive = TRUE)]);
Set <id> UserIds = new Set<id>();
FOR(PermissionSetAssignment ps : EmployeePermSet){
UserIds.add(ps.AssigneeId) ;
}
system.debug ('active users w perm set '+UserIds.size());
ActiveUsersWithPermissions = UserIds.size();
//create list of workers w user populated with perm set assigned - this is the true number of licenses allocated
list <vanahcm__worker__c> ProvisionedWorkers = new list <vanahcm__worker__c>([Select Name,VANAHCM__User__c from VANAHCM__Worker__c WHERE VanaHCM__User__c =: UserIds ORDER BY VanaHCM__Last_Name__c]);
system.debug('provisionedworkers '+ProvisionedWorkers.Size());
WorkersWithProvisionedUser = ProvisionedWorkers.Size();
//get list of users who have perm set but no worker connected
// line 28 to 36 not working - debug is correct but VF page not displaying anything
set <id> ProvisionedIds = new set<id>();
FOR(VANAHCM__Worker__c wpu : ProvisionedWorkers){
ProvisionedIds.add(wpu.VANAHCM__User__c);
}
UserIds.removeall(ProvisionedIds);
system.debug('userIDs2 '+userIds);
PermSetOnly = ([SELECT Id,Name from USER WHERE Id =: UserIds ORDER BY LastName]);
system.debug (PermSetOnly);
RETURN ProvisionedWorkers;
}
}
Visualforce Page
<apex:page controller="HCMLicensingController"> <p> There are <apex:outputText value=" {!WorkersWithProvisionedUser}"> </apex:outputText> Workers connected to Active Users that are provisioned the HCM Perm Set<br /> </p> <apex:outputPanel rendered="{!IF($Profile.Name = 'System Administrator',TRUE,FALSE)}"> Debug Info:<br /> Active Users w Perm Set: <apex:outputText value="{!ActiveUsersWithPermissions}"></apex:outputText><br /> Workers w/ Active User w Perm Set: <apex:outputText value="{!WorkersWithProvisionedUser}"></apex:outputText> <table> <apex:repeat value="{!PermSetOnly}" var="pso"> <tr> <td> <apex:outputText value="{!pso.Name}"></apex:outputText> </td> </tr> </apex:repeat> </table> </apex:outputPanel> <apex:variable value="{!1}" var="rowNum"/> <table style="border:1px;"> <apex:repeat value="{!ProvUsers}" var="u"> <tr> <td> <apex:outputText value="{!FLOOR(rowNum)}"/> </td> <td> <apex:outputText value="{!u.name}"></apex:outputText> </td> </tr> <apex:variable var="rowNum" value="{!rowNum + 1}"/> </apex:repeat> </table>