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


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){
    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">
        There are  <apex:outputText value=" {!WorkersWithProvisionedUser}"> </apex:outputText> Workers connected to Active Users that are provisioned the HCM Perm Set<br />
    <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>    
    <apex:repeat value="{!PermSetOnly}" var="pso">
    <apex:outputText value="{!pso.Name}"></apex:outputText>
    <apex:variable value="{!1}" var="rowNum"/>
    <table style="border:1px;">
    <apex:repeat value="{!ProvUsers}" var="u">
           <apex:outputText value="{!FLOOR(rowNum)}"/>
        <apex:outputText value="{!u.name}"></apex:outputText>
          <apex:variable var="rowNum" value="{!rowNum + 1}"/>


The reason PermSetOnly is null is because the order of getters is not predictable and you populate the variable via a separate getter on ProvUsers.

While there are many different styles to follow, the one I like is to use this pattern

 public class myController {
   public User[] PermSetOnly get {
      // logic to fetch the permSetOnly users
      return this.permSetOnly;
   private set;

   public VANAHCM__Worker__c[] Provusers get {
      // logic to fetch the Provisioned Users
      return this.provusers;
   private set;

   public myController() {}  // constructor


If you have common fetch logic between each getter, you can do that once in the constructor, or, have each getter call a common method that caches its result so the second call to the common method doesn't redo the SOQL.

  • 1
    Thanks will try using the constructor. If I was to use a common method as suggested, how do you cache the results? In an instance variable? – gorav Feb 3 '16 at 23:36
  • you cache in a controller instance variable - correct! – cropredy Feb 4 '16 at 1:50
  • Thanks @crop1645. Using the constructor worked perfectly. I tried but couldn't quite get it setup right using the pattern you described, but went back to what I knew and got it working. – gorav Feb 4 '16 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.