+ Start a Discussion
StaciStaci 

list of records for user with multiple business units

I have a multi picklist on the User record for Business Unit.  I have a VF Page that shows the list of licenses depending on the user logged in and their Business Unit.  

So for instance.  If my Business Unit is A and C, I want to see all licenses with a Business Unit of A and C.  

If I only have one option chosen for Business Unit on the User record, the User sees their licenses fine.  If the User record has more than one Business Unit chosen, the VF Page only shows column headers, no data.  How do I get it to show licenses for both (or more) Business Units?

This isn't all the code, the last half of the class is long and I didn't post it(Its for the first page block)
 

/*
Class/Method Name: LicenseList
Description: creates lists of licenses to be viewed on the LicenseSummaryHomePage VF Page for the License Community
Author/Date: Staci Gilmore 8/31/16
*/


public with sharing class LicenseList { 
private final License_Numbers__c ln; 
public user currentuser{get;set;} 
public id tobeEdited{get;set;}
public decimal aTotal{get;set;}
public decimal tTotal{get;set;}
public decimal aoTotal{get;set;}
public decimal Total{get;set;} 
//public List<AccountWrapper> wrappers{get;set;}
private Integer nextIdent=0;

public LicenseList(ApexPages.StandardSetController controller) { 
currentuser=new User(); 
currentuser=[Select Id, Business_Unit_new__c from User where Id=:userinfo.getuserId()]; 
this.ln = (License_Numbers__c)controller.getRecord(); 

} 

//------------------------------------------------------------------------------------

public List<License_Numbers__c> lntypes16 = new List<License_Numbers__c>();

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__c, One_Month_from_2016__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Running_License_Total__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2016' ORDER BY Order_Number__c, License_Type__c];
       

return lntypes16; 
} 


//-----------------------------------------------------------------------------
//Returns list of 2017 licenses from original order in contract
public List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();


public List <License_Numbers__c> getLicenseList17()
{ 

selectedTypes=[select id, Name, BU_Agrees_to_Pay__c, Sum_of_Cost_10__c, X2016_Subtotal__c, One_Month_from_2016__c, Comments__c , 
                      License_Type2__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, 
                      X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c 
               FROM License_Numbers__c 
               where Business_Unit__c =:currentuser.Business_Unit_new__c AND 
                     License_Year__c = '2017' AND 
                     Add_On__c = false 
               ORDER BY Order_Number__c, License_Type__c];
    
aTotal = 0.0;
tTotal = 0.0;       
          for(License_Numbers__c a:selectedTypes){
                aTotal = aTotal + a.X2017_Cost__c; 
                tTotal = tTotal + a.X2017_Subtotal__c;  
        }
return selectedTypes; 




} 


   



//----Added 2/6/17-------------------------------------------------------------------------
//Returns list of 2017 licenses that were added after the 2017 contract was signed
public List<License_Numbers__c> selectedTypesAddon = new List<License_Numbers__c>();
 
public List <License_Numbers__c> getLicenseList17Addon(){ 

selectedTypesAddon=[select id, Name, True_Up_Cost__c, Sum_of_Cost_10__c, X2016_Subtotal__c, BU_Agrees_to_Pay__c, One_Month_from_2016__c, Comments__c , License_Type2__c, Add_On__c, Annualized_Running_Total__c, X2017_Cost__c, Business_Unit__c,X2017_Total_Needed__c, X2016_Starting_Amount__c, X2017_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c where Business_Unit__c =:currentuser.Business_Unit_new__c AND License_Year__c = '2017'AND Add_On__c = True ORDER BY Order_Number__c, License_Type__c]; 
aoTotal = 0.0;
       
        for(License_Numbers__c a:selectedTypesAddon){
                aoTotal = aoTotal + a.True_Up_Cost__c;  
        }
return selectedTypesAddon; 
} 


}
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" sidebar="false">
<!------------------------------------------------------------------------------------------------------>
<!--Based on option chosen for License Type, will show description of that license type-->
<apex:pageBlock title="License Definitions">
<apex:form id="theForm">
<apex:pageBlockSection columns="1">
<apex:selectList label="Please select a License Type"  value="{!discountScheduleID}" size="1" >
   <apex:actionSupport event="onchange" action="{!displayDescription}" rerender="description"/>
   <apex:selectOptions value="{!schedules}" />
</apex:selectList> 

<apex:outputText label="Description" id="description" value="{!OutPutString}"/>

<br></br><br></br><br></br><br></br>
</apex:pageBlockSection>
</apex:form>


<!--------------------------------------------------------------------------------------------------


<apex:pageBlockTable value="{!LicenseList17Total}" var="lntot">

<apex:outputLink value="{!lntot.Id}">{!lntot.Name}</apex:outputLink>

<apex:column headerValue="                           ">

  <apex:facet name="footer">
  <apex:outputPanel layout="block" style="text-align:left"> 
  SLA Cost + Add-on Cost:
  <apex:outputText value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!Total}" />
    </apex:outputText>
  
  
  </apex:outputPanel>
  </apex:facet>
</apex:column> 
 

</apex:pageBlockTable>-->

</apex:pageBlock>



<!--------------------------------------------------------------------------------------------------------->
<apex:form id="theForm">
<apex:pageBlock id="blockId" title="2017 Licenses">
<!--<apex:pageBlockSection columns="1">

<tr>
<apex:outputText style="font-weight:800" label="Total Contract + Add-on Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!Total}" />
</apex:outputText>

<apex:outputText style="font-weight:800" label="Total 2017 SLA" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!aTotal}" />
</apex:outputText>

</tr>
</apex:pageBlockSection>-->

<!-------------------------------------------------------------------------------------------------->


<apex:pageBlockTable value="{!LicenseList17}" var="ln17">

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<!--ONLY NEEDED FOR LICENSE NEGOTIATIONS
<apex:column >
<apex:commandbutton value="Edit" rerender="blockId" rendered="{!!(tobeEdited == ln17.id)}">
    <apex:param assignTo="{!tobeEdited}" value="{!ln17.id}" name="ittobeedited"/>
</apex:commandbutton>
<apex:commandButton value="Save" action="{!saveRecord}" reRender="blockId" rendered="{!tobeEdited == ln17.id}"/>
</apex:column> -->

<apex:column value="{!ln17.Org__c}" />
<apex:column value="{!ln17.Business_Unit__c}"/>

<apex:column headerValue="BMS Code">
    <!--Allows it to be edited-->
    <apex:inputfield value="{!ln17.BMS_Code__c}" rendered="{!tobeEdited == ln17.id}"/>
    <!--After Save-->
    <apex:outputField value="{!ln17.BMS_Code__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column>    

<apex:column value="{!ln17.License_Type2__c}"/>

<apex:column headerValue="BU Agrees to Pay">
    <apex:inputfield value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.BU_Agrees_to_Pay__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column> 

<apex:column value="{!ln17.Monthly_Unit_Price__c}" />

<apex:column headerValue="2017 Number Needed">
    <apex:inputfield value="{!ln17.X2017_Total_Needed__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.X2017_Total_Needed__c}" rendered="{!!(tobeEdited == ln17.id)}"/>

 
 
</apex:column> 

<apex:column headerValue="Annualized Cost" value="{!ln17.X2017_Subtotal__c}">
<!--<apex:facet name="footer">
    <apex:outputText value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!tTotal}" />
    </apex:outputText>

   
</apex:facet>-->


</apex:column>
<apex:column headerValue="Sum of Cost + 10%" value="{!ln17.Sum_of_Cost_10__c}"/>

<apex:column headerValue="1 month from 2016" value="{!ln17.One_Month_from_2016__c}">
    <apex:facet name="footer">
  <apex:outputPanel layout="block" style="text-align:right"> 
  SLA Cost:

  </apex:outputPanel>
  </apex:facet>
  </apex:column>

<apex:column headerValue="Total 2017 SLA" value="{!ln17.X2017_Cost__c}">
  <apex:facet name="footer">
              <apex:outputText style="font-weight:800" value="${0, number, ###,###,###,##0.00}">
              <apex:param value="{!aTotal}" />
              </apex:outputText>
               
</apex:facet>
</apex:column>
<apex:column headerValue="Comments">
    <apex:inputfield value="{!ln17.Comments__c}" rendered="{!tobeEdited == ln17.id}"/>
    <apex:outputField value="{!ln17.Comments__c}" rendered="{!!(tobeEdited == ln17.id)}"/>
</apex:column> 


</apex:pageBlockTable>


</apex:pageBlock>





<!----ONLY NEEDED FOR LICENSE NEGOTIATIONS-------------------------------------------------------------------------------------->
<!--<apex:pageBlock title="New Licenses Needed for 2017" id="newblock">

<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">

<apex:column HeaderValue="Org">
<apex:inputField value="{!wrapper.lic.Org__c}" />
</apex:column>

<apex:column HeaderValue="Business Unit">
<apex:inputField value="{!wrapper.lic.Business_Unit__c}" />
</apex:column>

<apex:column HeaderValue="License Type">
<apex:inputField value="{!wrapper.lic.License_Type2__c}"  />
</apex:column>

<apex:column HeaderValue="BU Agrees to Pay">
<apex:inputField value="{!wrapper.lic.BU_Agrees_to_Pay__c}" />
</apex:column>

<apex:column HeaderValue="2017 Number Needed">
<apex:inputField value="{!wrapper.lic.X2017_Total_Needed__c}"/>
</apex:column>

<apex:column HeaderValue="Comments">
<apex:inputField value="{!wrapper.lic.Comments__c}"/>
</apex:column>


</apex:pageBlockTable>


</apex:pageBlock>-->

<!--<apex:commandButton value="Save" action="{!addsave}" />-->




        

<apex:pageBlock id="blockId2" title="2017 Add-Ons">
<!--
<apex:pageBlockSection columns="1">

<td>
<apex:outputText style="font-weight:800" label="Total Add-on Cost" value="${0, number, ###,###,###,##0.00}">
    <apex:param value="{!aoTotal}" />
</apex:outputText>
</td>

</apex:pageBlockSection>-->

<!-------------------------------------------------------------------------------------------------->


<apex:pageBlockTable value="{!LicenseList17Addon}" var="ln17ao">

<apex:outputLink value="{!ln17ao.Id}">{!ln17ao.Name}</apex:outputLink>
<!--ONLY NEEDED FOR LICENSE NEGOTIATIONS
<apex:column >
<apex:commandbutton value="Edit" rerender="blockId2" rendered="{!!(tobeEdited == ln17ao.id)}">
    <apex:param assignTo="{!tobeEdited}" value="{!ln17ao.id}" name="ittobeedited"/>
</apex:commandbutton>
<apex:commandButton value="Save" action="{!saveAddonRecord}" reRender="blockId2" rendered="{!tobeEdited == ln17ao.id}"/>
</apex:column> -->

<apex:column value="{!ln17ao.Org__c}" />

<apex:column headerValue="BMS Code">
    <!--Allows it to be edited-->
    <apex:inputfield value="{!ln17ao.BMS_Code__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <!--After Save-->
    <apex:outputField value="{!ln17ao.BMS_Code__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column>    

<apex:column value="{!ln17ao.License_Type2__c}"/>

<apex:column headerValue="BU Agrees to Pay">
    <apex:inputfield value="{!ln17ao.BU_Agrees_to_Pay__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.BU_Agrees_to_Pay__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column> 

<apex:column value="{!ln17ao.Monthly_Unit_Price__c}" />

<apex:column headerValue="2017 Number Needed">
    <apex:inputfield value="{!ln17ao.X2017_Total_Needed__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.X2017_Total_Needed__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column>    

<apex:column headerValue="Annualized Cost" value="{!ln17ao.X2017_Subtotal__c}" >
 <apex:facet name="footer">
      <apex:outputPanel layout="block" style="text-align:right"> 
      True-up Cost: 
      </apex:outputPanel>
  </apex:facet>
</apex:column>
  
<apex:column headerValue="2017 True-Up Cost" value="{!ln17ao.True_Up_Cost__c}">
  <apex:facet name="footer">
        <apex:outputText style="font-weight:800" value="${0, number, ###,###,###,##0.00}">
        <apex:param value="{!aoTotal}" />
        </apex:outputText>
</apex:facet> 
</apex:column>
<apex:column headerValue="Comments">
    <apex:inputfield value="{!ln17ao.Comments__c}" rendered="{!tobeEdited == ln17ao.id}"/>
    <apex:outputField value="{!ln17ao.Comments__c}" rendered="{!!(tobeEdited == ln17ao.id)}"/>
</apex:column> 


</apex:pageBlockTable>


</apex:pageBlock>
</apex:form>

<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="2016 Licenses">
<apex:pageBlockSection columns="1">

<apex:pageBlockTable value="{!LicenseList}" var="ln">

<apex:outputLink value="{!ln.Id}">{!ln.Name}</apex:outputLink>

<apex:column value="{!ln.Org__c}" />
<apex:column value="{!ln.Business_Unit__c}" />
<apex:column value="{!ln.BMS_Code__c}" />
<apex:column value="{!ln.License_Type__c}" />
<apex:column value="{!ln.Monthly_Unit_Price__c}" />
<apex:column headerValue="2016 Starting Amount" value="{!ln.X2016_Starting_Amount__c}" />
<apex:column headerValue="2016 Running License Total" value="{!ln.Running_License_Total__c}" />
<apex:column headerValue="Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Charge" value="{!ln.X2016_Cost__c}"/>
<apex:column headerValue="One Month charge in 2017" value="{!ln.One_Month_from_2016__c}"/>

</apex:pageBlockTable>
</apex:pageBlockSection>

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>




<!--------------------------------------------------------------------------------------------------------->
</apex:page>

 
Best Answer chosen by Staci
AjazAjaz
Hi Staci,

In case of multi select picklists, when you try to print the value present in MS picklist field, you will get values seperated with a semi-colon ';'. In your case, lets say if there are 2 business units, A & B, when you try to print the values of business units, it will print 'A;B'. Thats the reason why the SOQL is unable to fetch records. I suggest you to split the string by ; and then use the resultant list in the SOQL.

For example,

List<String> bUnitsList = currentuser.Business_Unit_new__c.split(';');

in soql, add like this, FROM License_Numbers__c whereBusiness_Unit__c in : bUnitsList

I hope this solves. Please give a thumbsup if it was helpful to you as it may help others.

Regards,
Zaja.

All Answers

AjazAjaz
Hi Staci,

In case of multi select picklists, when you try to print the value present in MS picklist field, you will get values seperated with a semi-colon ';'. In your case, lets say if there are 2 business units, A & B, when you try to print the values of business units, it will print 'A;B'. Thats the reason why the SOQL is unable to fetch records. I suggest you to split the string by ; and then use the resultant list in the SOQL.

For example,

List<String> bUnitsList = currentuser.Business_Unit_new__c.split(';');

in soql, add like this, FROM License_Numbers__c whereBusiness_Unit__c in : bUnitsList

I hope this solves. Please give a thumbsup if it was helpful to you as it may help others.

Regards,
Zaja.
This was selected as the best answer
StaciStaci
Thanks @Ajaz!  That worked!