• Staci
  • NEWBIE
  • 225 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 3
    Likes Received
  • 0
    Likes Given
  • 169
    Questions
  • 185
    Replies
Wondering if I get an email with the most recent case comment and I reply back, is there a way to have it save as a case comment in the case it came from?  We do not use email-to-case as we don't want cases created from emails.  Just want the emails someone replies to to save as a case comment on the case they came from. 
  • April 01, 2019
  • Like
  • 0
I have a sharing rule set up to allow a customer to see several different worksite accounts.  His account is on a worksite that is under one partner.  Some of the other worksites are under another partner.  These partners cannot see each others cases, worksites or contacts.  The partner that cannot see this customer needs to add him as a contact on one of their worksites.  I hope this makes sense.  How can I share a certain contact across 2 partners?

Contact User with Account Name of Worksite B

Partner A                                      Partner B
Worksite 1                                    Worksite A
Worksite 2                                    Worksite B
Worksite 3                                    Worksite C

Public Group = Customer

Sharing Rule = account name = Worksite 1, Worksite 2, Worksite 3, Worksite A, Worksite B, Worksite C
Shared with Public Group = Customer

Partner A needs to assign Contact User to a case for Worksite 3, cannot see the contact as it is under Worksite B at the other partner.
  • September 26, 2018
  • Like
  • 0
I'm making an escalate case button for our customers to use.  I need the funtionality to assign the case to a generic support queue if a checkbox is true, if not I need it to assign the case to the corresponding partner queue, which are set in the case assignment rules.  Is there a way to invoke the assignment rules in the javascript button? 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 


if('{!Case.CW_Advance_Support_Needed__c}' == true) 
{ 
caseObj.OwnerId = '00G30000001oUSL'; 
caseObj.Status = 'In Progress'; 

}else{ 


caseObj.CW_Advance_Support_Needed__c='True'; 
caseObj.Escalated_Date_Time__c=new Date().toJSON(); 

} 

if('{!Case.Incident_First_Response__c}'=='') 
{ 
caseObj.Incident_First_Response__c=new Date().toJSON(); 
} 

var result = sforce.connection.update([caseObj]); 
window.location.href=window.location.href;
  • September 18, 2018
  • Like
  • 0
I have a custom object that has a lookup to Opportunity.  I have an apex page that renders a pdf. 

I need to get the primary contact of the related opportunity onto the pdf.  I have found and tried this, with no avail.  It gives me an aggregate error:
 Aggregate Relationship is used in an unsupported complex expression containing 'Opportunity__r.opportunitycontactroles'
<apex:outputPanel>
             <apex:repeat value="{!Machine_Quote__c.Opportunity__r.OpportunityContactRoles}" var="opcr" >
                     <apex:outputText rendered="{!opcr.IsPrimary == True}">
                         <td><apex:outputField value="{!opcr.ContactId}"/></td>
                     </apex:outputText>
             </apex:repeat>
             </apex:outputPanel>

Please help??  TIA!
  • January 03, 2018
  • Like
  • 0
I have a button that renders a pdf.  In the pdf is a finance table, calculating the financing cost with different percentages for money down (5%, 10% & 20%)
I have 4 cost fields(tax, warranty, list price, part costs) that have to added to get the the total cost of an item.  I then need to take 5%, 10% and 20% of that total cost and show the result.  Can I accomplish this in a vf page or do I need to use the controller?  Any help with examples would be great.  
 
  • January 03, 2018
  • Like
  • 0
I have a custom object where the record has a button to create an opportunity.  There is a lookup on the custom object that fills in the opportunity name when the opportunity is created through the button.  I have 2 lines of code I can't get covered and I'm not sure how to accomplish, please help!  TIA!

These are the 2 lines I can't get covered
acc.Related_to_Opportunity__c = MapAccCom.get(acc.id);
        oppList.add(acc);

trigger IDM_GSVT_UpdateRelatedOpportunity on EOMPDiscountRequest__c (before insert) {
    //Name - field to be added to Related_to_Opportunity
    //Related_to_Opportunity__c //look up on GSVT record to be updated
    Map<Id, Id> MapAccCom = new Map<Id, Id>();
    for(EOMPDiscountRequest__c comm:trigger.new)
    {
        MapAccCom.put(comm.Name,comm.id);
    }
    List<EOMPDiscountRequest__c> disc = [Select id from EOMPDiscountRequest__c where id IN :MapAccCom.keyset()];
    List<EOMPDiscountRequest__c> oppList = new List<EOMPDiscountRequest__c>();
    for(EOMPDiscountRequest__c acc : disc)
    {
        acc.Related_to_Opportunity__c = MapAccCom.get(acc.id);
        oppList.add(acc);
    }
    update oppList;

}

@isTest
private class IDM_GSVT_UpdateRelatedOpportunityTest {
 private static EOMPDiscountRequest__c createDiscountRequest(string dealerCode, string marketSegment, string segmentType, string discountType, string majorClass) {
        Id OTOretro = Schema.SObjectType.EOMPDiscountRequest__c.getRecordTypeInfosByName().get('OTO Retroactive').getRecordTypeId();
        EOMPDiscountRequest__c discountRequestObj = new EOMPDiscountRequest__c(Dealer_Code__c = dealerCode,
                                                                                Market_Segment_Picklist__c = marketSegment,
                                                                                Major_Class__c = majorClass,
                                                                                Industry_GASD__c = segmentType,
                                                                                Valid_From__c = system.today(),
                                                                                Valid_To__c = system.today(),
                                                                                Discount_Type__c = discountType,
                                                                                recordTypeId = OTOretro,
                                                                                M_Rate__c = 25);
        insert discountRequestObj;
        return discountRequestObj;
    }
private static testMethod void testController(){    
    Map<String,schema.recordtypeinfo> rtMapByName=schema.sobjecttype.account.getRecordtypeInfosByName();
        Id ryById=rtMapByName.get('Customer/Partner').getRecordTypeId();
        Account acc = new Account(Name = 'Account1',RecordtypeId = ryById,Account_Usage__c='GCI');
        insert acc;
        
        Map<String,schema.recordtypeinfo> rtdelMapByName=schema.sobjecttype.account.getRecordtypeInfosByName();
        Id rydelById=rtdelMapByName.get('Dealer').getRecordTypeId();
        Account delacc = new Account(Name = 'delAccount1',RecordtypeId = rydelById,Account_Usage__c='GCI');
        insert delacc;
    
       Id oppRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Parts & Service Opportunity').getRecordTypeId();
        Opportunity oppty = new Opportunity();
        oppty.Name = 'test1';
        oppty.RecordTypeId = oppRecordTypeId;
        oppty.AccountId = acc.id;
        oppty.Major_Class__c = 'CSA';
        oppty.Dealer__c = delacc.id;
        oppty.Marketing_Campaign__c = 'GD UC';
        oppty.Amount = 50000.00;
        oppty.LeadSource = 'other';
        oppty.CurrencyIsoCode = 'INR';
        oppty.StageName = 'Closed Won';
        oppty.CloseDate = system.today();
        oppty.Description = 'test';
        oppty.Primary_Lost_Sale_Reason__c = 'Product';
        oppty.Primary_Lost_Sale_Reason_Detail__c = 'Worktool';
        oppty.Winning_Competitor_legacy__c = 'BYG';
        oppty.GASD_Industry__c = 'Construction Industries';
        insert oppty;
        }
        
}

 
  • October 02, 2017
  • Like
  • 0
I have a custom Clone button with the following:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

alert("----"+'{!$UserRole.Name}'+"-----"+'{!User.Account_Name_Dealer_Text__c}'+"-------"); 
IF(CONTAINS($UserRole.Name,User.Account_Name_Dealer_Text__c),window.parent.location.href="/{!Case.Id}/e?clone=1&retURL=/{!Case.Id}",alert("You are not a contact for this dealer."))

I'm trying to see if account name is contained in the role of the logged in user.  I'm getting IF is not defined when the button is clicked.  The logged in user and account do match in my testing scenerio.
  • June 13, 2017
  • Like
  • 0
Is there a way to get the current logged in user's account name in a custom JavaScript button?
  • May 11, 2017
  • Like
  • 0
I'm looking for a way to limit a custom clone button.  We will be opening up cases so that all partner portal users can see all cases, not just what they own.  When I log in as one partner user, I can see other partner accounts as expected, BUT I can also click our custom Clone button and create a new case for that partner, which should be happen.  Is there a way to limit this in a JavaScript button?  If so, how?
  • May 09, 2017
  • Like
  • 0
I have a custom object with a custom Send An Email button that will default the Related To in the subject line of the outbound email message.  It sends fine.  What I want, is if anyone replies to that email I want another entry made in the Activity History of that inbound email message.  I can see in the debug logs that the emails are coming back in, but I can't find them anywhere (floating around in SF space!)  How do I get them associated with the custom object when they come back into SF?
Here's my email handler
global class serviceInquiryHandler implements Messaging.InboundEmailHandler {
         
          
      global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
          Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
          
      if(email.subject.contains('Service Inquiry'))
      {
          
            
            try
            {
                 //string ccAddy = envelope.ccAddress;
                 system.debug('I get here' + email.subject + '--------------------------------------------');
                 EmailMessage mes = new EmailMessage();
                  //mes.CcAddress = envelope.ccAddresses;
                  mes.ToAddress = envelope.toAddress;
                  mes.FromName = email.FromName;
                  mes.FromAddress = envelope.fromAddress;
                  //mes.RelatedTo = email.subject.substringAfter('Service Inquiry');
                  mes.HtmlBody = email.plainTextbody;
                  mes.Subject = email.subject;
                  
                  insert mes;
                  //to save attachment to activity
                  //for(Messaging.Inboundemail.BinaryAttachment bAttachment:
                  //email.binaryAttachments) {
                      //Attachment attachment = new Attachment();
                      //attachment.Name = bAttachment.fileName;
                      //attachment.Body = bAttachment.body;
                      //attachment.ParentId = mes.Id;
                      //insert attachment;
                  //}               
                
                  result.success = true;
            }catch (Exception e){
                  result.success = false;
                  result.message = 'Oops, I failed.' + e.getMessage();
            }
              return result;
      }
      return null;
 
  }
}

 
  • April 25, 2017
  • Like
  • 0
I have a test class that is 68% covered.  I have 2 lines throughout that I cannot get covered.  Can anyone help me get them covered?
Its the 2 lines after the else statement.  
 
if (oldCase.Substatus__c == 'Open with Cat Support') {
                                // Log into the "Open with Cat Support" bucket
                                if(c.Accumulated_Duration_Open_with_Cat_Supp__c != Null) {
                                  c.Accumulated_Duration_Open_with_Cat_Supp__c += elapsedHours;
                                }
                                else {
                                    c.Accumulated_Duration_Open_with_Cat_Supp__c = 0.0;
                                    c.Accumulated_Duration_Open_with_Cat_Supp__c += elapsedHours;
                                }
                            }

 
  • April 17, 2017
  • Like
  • 0
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>

 
  • March 16, 2017
  • Like
  • 0
I have the below method that I don't understand how to cover in my test class.  Can anyone help please?
 
@future
    public static void createLicenseGroups()
    {

        //Query for the Account record types
        List<RecordType> rtypes = [SELECT Name, Id FROM RecordType WHERE sObjectType='License__c' AND isActive=true];
     
        //Create a map between the Record Type Name and Id for easy retrieval
        Map<String,String> LicRecTyp = new Map<String,String>{};
        for(RecordType rt: rtypes)
           LicRecTyp.put(rt.Name,rt.Id);
           
        ID gID = LicRecTyp.get('License Group');

        List<License__c> licenseGroups = new List<License__c>();
        
        Map<STRING, Schema.sObjectField> fieldsMap = Schema.SObjectType.User.fields.getMap();
        for (Schema.PicklistEntry p : fieldsMap.get('SF_License_Owner_Type__c').getDescribe().getPicklistValues())   
            licenseGroups.add(new License__c(RecordTypeID = gID, Owner_Group_Name__c = p.getLabel(), Licenses_Owned__c = 9999, Licenses_Used__c = 0));    
        
        insert licenseGroups;
}

 
  • February 22, 2017
  • Like
  • 0
I currently have a custom object called Licenses__c.  The Apex code doesn't work properly and I need to redo it.  I need to show a list that shows the license group (Business Unit - License Type) Example: ECRM - Full Cloud, ECRM - Partner Community, etc.  I have several business units in one org so I need a way to regulate the licenses.  When a user is created with a specific license group, I want the counts to update (increase the number used & decrease the number available).  Similar when a user is deactivated, reduce the number used and increase the number available.  I also need to take into account when a user is moved from one license group to another.  Is there any examples of this somewhere or can someone start me in the right direction?
  • January 05, 2017
  • Like
  • 0
I have existing code, which doesn't work completely.  I have a custom object called Licenses__c.  I have a trigger that is supposed to update the licenses used and licenses available for a certain group when a new user is created, or an existing user is updated.  I have added new license groups and it doesn't seem to like to update those.  It will update the existing groups just fine.  Not sure why.  I inherited this code, so please let me know if you have questions
 
trigger updateLicense on User (Before Insert, After Insert, Before Update, After Update) 
{
    User cfU = trigger.new[0];
    IF (cfU.UserType != 'CsnOnly')       
    {
    Integer lGroups = [SELECT count() FROM License__c];
            
        ID gID = License__c.SObjectType.getDescribe().getRecordTypeInfosByName().get('License Group').getRecordTypeId();
                
        IF (Trigger.isBefore)
        {
            ID orgId = UserInfo.getOrganizationId();
            IF ((orgId != Label.PROD_ORG_ID) && (lGroups == 0))
                LicenseUser.createLicenseGroups();    
            IF ((Test.isRunningTest()) && (lGroups == 0))
                TestLicenseUser.createTestGroups();

            MAP<String,ID> nuMap = new MAP<String,ID>();
            MAP<ID,Decimal> usedMap = new MAP<ID,Decimal>();
            MAP<ID,Decimal> ownedMap = new MAP<ID,Decimal>(); 
            List<String> inActiveUser = new List<String>();

            for (License__c l : [SELECT ID,Owner_Group_Name__c, Licenses_Used__c, Licenses_Owned__c from License__c where RecordTypeId = :gID]) 
            {
               nuMap.put(l.Owner_Group_Name__c,l.ID);   
               usedMap.put(l.ID,l.Licenses_Used__c);
               ownedMap.put(l.ID,l.Licenses_Owned__c);
            }
            
            system.debug('nuMap------------'+nuMap);
            integer uCount = 0;
            for(User u: Trigger.New)
            {                                
                ID ownerId = nuMap.get(u.SF_License_Owner_Type__c);
                system.debug('ownerId------------'+ownerId);
                system.debug('usedMap------------'+usedMap);
                Decimal usedCnt = usedMap.get(ownerId);
                
                system.debug('usedCnt------------'+usedCnt);
                          
                IF (u.SF_License_Owner_Type__c == null)
                    u.SF_License_Owner_Type__c.addError('The SF License Owner/Type field must be populated.');
            
                IF (u.UserType == 'CsnOnly')
                {
                    uCount++;
                    continue;
                }            

                Boolean noLicense = (usedCnt >= ownedMap.get(ownerId)),
                        deActivate = false,
                        updActive = false,
                        updOwner = false;
                        
                IF (Trigger.isInsert)
                { 
                    IF (noLicense) {deActivate = true;}
                }
            
                IF (Trigger.isUpdate)
                {
                    updActive = (u.IsActive != trigger.old[uCount].IsActive);
                    updOwner = (u.SF_License_Owner_Type__c != trigger.old[uCount].SF_License_Owner_Type__c);
                
                    IF (updActive)        //IF isActive flag changed on user record
                    {
                        IF (u.isActive)    //IF user was activated
                        {
                            IF (noLicense) {deActivate = true;}        //IF no license(s) then de-activate user
                        }
                        ELSE {deActivate = true;}        //User de-activated, flag to update license counts
                    }
                
                    IF (updOwner)        //IF SF_License_Owner_Type__c changed
                    {
                        IF ((u.SF_License_Owner_Type__c != null) && (u.isActive))        //IF License Owner populated and user is active
                        {
                            IF (noLicense) {deActivate = true;}        //IF no license(s) then de-activate user
                        }
                    }
                }
            
                IF (deActivate)
                {                               
                    IF ((!Trigger.isInsert) && (trigger.old[uCount].SF_License_Owner_Type__c != null))    //IF de-activating a user while
                    {                                                                             //License Owner populated or changed
                        ID ownerId2 = nuMap.get(trigger.old[uCount].SF_License_Owner_Type__c);                  
                        Decimal usedCnt2 = usedMap.get(ownerId2);

                        usedMap.remove(ownerId2);
                        usedCnt2--;        //decrement license used count by 1
                        usedMap.put(ownerId2,usedCnt2);  
                    }
                        
                    IF (u.isActive)        //De-Activating user
                    {
                        Trigger.New[uCount].isActive = FALSE;
                        inActiveUser.add(u.firstname + ' ' + u.lastname + ' using License from Group: ' + u.SF_License_Owner_Type__c);                  
                    }
                }
                ELSE        //Activating user
                {
                    system.debug('usedMap before remove------------'+usedMap);
                    usedMap.remove(ownerId);
                    system.debug('usedMap after remove------------'+usedMap);
                    system.debug('usedCnt-----------'+usedCnt);
                    usedCnt++;        //increment license used count by 1
                    usedMap.put(ownerId,usedCnt);            
                }        
                uCount++; 
          
                IF (InActiveUser.size() > 0)        //Notify the user triggering invocation via chatter and email    
                {                                   //that user(s) was/were de-activated due to insufficient licenses
                    Messaging.reserveSingleEmailCapacity(2);  
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

                    User u2=[Select email from User where id=:UserInfo.getUserId()];
                    List<String> UserEmail = new List<String>();
                    UserEmail.add(u2.email);
            
                    mail.setToAddresses(UserEmail);
                    mail.setSenderDisplayName('Salesforce Support');
                    mail.setSubject('IMPORTANT: Insufficient Licenses available to Activate users!');

                    String body = 'The following users were de-activated due to insufficient licenses being available: \n';
                    for(Integer i = 0; i < InActiveUser.size(); i++)
                    {
                        body = body + InActiveUser.get(i) + '\n';
                    }
                
                    mail.setPlainTextBody(body);
            
                    postChatterFeedToUser.postToUser(UserInfo.getUserId(),body);
                    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });        
                }
            }
        }

        IF (Trigger.isAfter)
        {        
            List<ID> delUsers = new List<ID>();
            MAP<ID,String> addUsers = new MAP<ID,String>();

            integer userCount = 0;        
            for(User u2 : Trigger.New) 
            {                       
                IF (u2.UserType == 'CsnOnly')
                {
                    userCount++;
                    continue;
                }

                Boolean updActive = false,
                        updOwner = false,
                        isAdd = false,
                        isDel = false;            
                         
                IF (Trigger.isInsert)
                {
                    IF(u2.IsActive) {isAdd = true;}          //IF user is being activated, add to License table      
                }
            
                IF (Trigger.isUpdate)
                {
                    updActive = (u2.IsActive != trigger.old[userCount].IsActive);
                    updOwner = (u2.SF_License_Owner_Type__c != trigger.old[userCount].SF_License_Owner_Type__c);
                
                    IF (updActive)        //IF isActive flag changed on user record
                    {
                        IF (u2.isActive) {isAdd = true;}        //IF user is being activated, add to License table
                        ELSE{isDel = true;}                     //ELSE delete it from License table
                    }
                
                    IF ((updOwner) && (u2.isActive))        //IF updating License Owner on active user
                    {
                        isDel = true;        //Delete from previous group (SF_License_Owner_Type__c before) on License table if needed
                    
                        IF (u2.SF_License_Owner_Type__c != null)
                        {
                            isAdd = true;        //Add to the current group (SF_License_Owner_Type__c after) on License
                        }
                    }
                }
            
                IF (isAdd)
                {
                    addUsers.put(u2.ID,u2.SF_License_Owner_Type__c);        //Add user to license addition list
                }
        
                IF (isDel)
                {
                    IF (trigger.old[userCount].SF_License_Owner_Type__c != null)        //Only delete if prior value existed
                    {
                        delUsers.add(trigger.old[userCount].Id);        //Add user to license removal list
                    }
                }
                                           
                UserCount++;
            }  
    
            IF (delUsers.size() > 0)
            {
                LicenseUser.delLicenseUser(delUsers);        
            }
    
            IF (addUsers.size() > 0)
            {
                LicenseUser.addLicenseUser(addUsers);
            }
        }
    }    
}

 
  • January 04, 2017
  • Like
  • 0
I have the following code.  Business_Unit_new__c in the User object is the multipicklist.  
I want to pull records from the License Numbers object where the Business Unit (picklist) from the License record is equal to the Business Unit of the current user (multipicklist).  The users may have more than 1 Business Unit assigned to them.

I've tried WHERE Business_Unit__c INCLUDES (:currentuser.Business_Unit_new__c) and it errors saying includes can only be used with a multipick list

If I try 
currentuser.Business_Unit_new__c INCLUDES (:Business_Unit__c) it errors saying it doesn't understand the relationship with currentuser.

How do I fix this?(this is not the complete code, jus tthe snipit that i need the query in)
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 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(); 

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 

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

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

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__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; 
}



 
  • November 02, 2016
  • Like
  • 0
I have the following code, the last section has fields to add more licenses to the list.  After Save, I'd like the fields to return to blank or None, or whatever they were before the use filled them in.  Right now, if I F5, it adds another license to the list.  If I try to change the values and click save it errors, and then adds the previous options to the list again.
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" showHeader="false" 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:pageBlock>
<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="Current 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="2016 Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Cost" value="{!ln.X2016_Cost__c}"/>

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

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>



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

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

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


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

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<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 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_Type__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="2017 Annualized Cost" value="{!ln17.X2017_Subtotal__c}" />

<apex:column headerValue="Estimated 2017 Cost" value="{!ln17.X2017_Cost__c}"/>


</apex:pageBlockTable>

</apex:pageBlock>

<!------------------------------------------------------------------------------------------>
<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_Type__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}" onclick=""/>
</apex:column>

</apex:pageBlockTable>


</apex:pageBlock>
<apex:commandButton value="Save" action="{!save}" />

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

        
</apex:form>

<!--------------------------------------------------------------------------------------------------------->
</apex:page>
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 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(); 

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 

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

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

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__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; 
} 


//-----------------------------------------------------------------------------
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, 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' 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; 
} 
    public void saveRecord(){ 
    License_Numbers__c tobeupdated;
    for(License_Numbers__c temp:selectedTypes){
        if(temp.id==tobeEdited){
            tobeupdated = temp;
            
         }
     }
        update selectedTypes;
        tobeEdited = null;
    } 
//--------------------------------------------------------------------------------------------    

public List<License_Numbers__c> addlic {get; set;} 
  
public PageReference save()
{
    List<License_Numbers__c> addlic=new List<License_Numbers__c>();
    for(AccountWrapper wrap:wrappers)
    {
       License_Numbers__c lic = wrap.lic;
       lic.RecordTypeID = '012Q00000009F7P';
       lic.License_Year__c = '2017';
       addlic.add(wrap.lic);
    }
        
    insert addlic;
    //addlic = null;
    
    return new PageReference('/apex/LicenseSummaryHomePage');
         
}

public class AccountWrapper
{
    public License_Numbers__c lic{get; private set;}
    public Integer ident{get; private set;}
    
    
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        lic=new License_Numbers__c();
            
    }
}  //There's a lot more code here for the Schedules part - doesn't pertain to my problem
}

User-added image
 
  • October 17, 2016
  • Like
  • 0
Can someone please explain (and possibly fix) why the last section on my VF Page falls out of the frame?  The other frames stay within the "page" but the last section falls off.  

User-added image
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" showHeader="false" 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:pageBlock>
<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="Current 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="2016 Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Cost" value="{!ln.X2016_Cost__c}"/>

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

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>



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

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

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


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

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<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 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_Type__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="2017 Annualized Cost" value="{!ln17.X2017_Subtotal__c}" />

<apex:column headerValue="Estimated 2017 Cost" value="{!ln17.X2017_Cost__c}"/>


</apex:pageBlockTable>

</apex:pageBlock>

<!------------------------------------------------------------------------------------------>
<apex:pageBlock title="New Licenses Needed for 2017">

<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="BMS Code">
<apex:inputField value="{!wrapper.lic.BMS_Code__c}" />
</apex:column>

<apex:column HeaderValue="License Type">
<apex:inputField value="{!wrapper.lic.License_Type__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="License Year">
<apex:inputField value="{!wrapper.lic.License_Year__c}" />
</apex:column>

</apex:pageBlockTable>


</apex:pageBlock>
<apex:commandButton value="Save" action="{!save}"/>


</apex:form>

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

 
  • October 13, 2016
  • Like
  • 0
I have a test class started, got the dummy data created and now I'm not sure where to go.

How do you write a test class for all this??  Can't SF create something that would automatically create the test class for you????
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 id tobeAdded{get;set;}
public List<AccountWrapper> wrappers{get;set;}
public static Integer addCount{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(); 

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 

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

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

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__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; 
} 


//-----------------------------------------------------------------------------
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, 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' 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; 
} 
    public void saveRecord(){ 
    License_Numbers__c tobeupdated;
    for(License_Numbers__c temp:selectedTypes){
        if(temp.id==tobeEdited){
            tobeupdated = temp;
            
         }
     }
        update selectedTypes;
        tobeEdited = null;
    } 
//--------------------------------------------------------------------------------------------    

public List<License_Numbers__c> addlic {get; set;} 
  
public PageReference save()
{
    List<License_Numbers__c> addlic=new List<License_Numbers__c>();
    for(AccountWrapper wrap:wrappers)
    {
        addlic.add(wrap.lic);
    }
    insert addlic;
    
    return new PageReference('/apex/LicenseSummaryHomePage');
}

public class AccountWrapper
{
    public License_Numbers__c lic{get; private set;}
    public Integer ident{get; private set;}
    
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        lic=new License_Numbers__c();
    }
}   

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

public SelectOption[] getSchedules() {
        return new SelectOption[] { 
            new SelectOption('Value0', '--None--'),
            new SelectOption('Value1', 'Value1'),
            new SelectOption('Value2', 'Value2'), 

  };

    }
public String discountScheduleID { get; set; }

//--------------------------------------------------------------
 Public string OutPutString{get;set;}
 Public String SelectOption;
public void displayDescription(){
if (discountScheduleID == 'Value1')
{
OutPutString = 'No Description Available' ;
}else if (discountScheduleID == 'Value2')
    {
        OutPutString = 'No Description Available' ;
}}





 
@isTest 
private class LicenseListTest{
   
   static testMethod void LicenseListTest(){
        Profile p = [SELECT Id FROM Profile WHERE Name='Community Super User' limit 1]; 
        //create a user
        UserRole r = [SELECT Id FROM userrole WHERE name = 'CM User' limit 1];
        
        User u1 = new User(LastName = 'Test Class',
                                    Username = 'CRMUser@Test.com',
                                    UserRoleId = r.Id,
                                    Email = 'CRMUser@Test.com',
                                    Alias = 'tclass',
                                    CommunityNickname = 'tclass',
                                    TimeZoneSidKey = 'Asia/Kolkata',
                                    LocaleSidKey = 'en_US',
                                    EmailEncodingKey = 'UTF-8', 
                                    ProfileId = p.Id,
                                    LanguageLocaleKey = 'en_US',
                                    Business_Unit__c = 'GCI');
        insert u1;

}
static testMethod void LicenseList_test() {

//create a license Record
        License_Numbers__c ln1 = new License_Numbers__c(
                                     Business_Unit__c = 'GCI', 
                                     X2016_Starting_Amount__c = 5, 
                                     BMS_Code__c = 'X1357', 
                                     License_Type__c = 'Service Cloud - Unlimited Edition', 
                                     Monthly_Unit_Price__c = 83.00, 
                                     Running_License_Total__c = 500, 
                                     Org__c = 'CRM Innovation', 
                                     License_Year__c = '2016');
        insert ln1;
        
         //create a license Record
        License_Numbers__c ln2 = new License_Numbers__c(
                                     Business_Unit__c = 'GCI', 
                                     X2016_Starting_Amount__c = 5, 
                                     BMS_Code__c = 'X1357', 
                                     License_Type__c = 'Analytics Cloud - Wave Analytics Platform', 
                                     Monthly_Unit_Price__c = 52.50, 
                                     Org__c = 'CRM Innovation', 
                                     License_Year__c = '2016');
        insert ln2;
}



static testMethod void LicenseList17_test() {
//create a license Record
        License_Numbers__c ln3 = new License_Numbers__c(
                                     Business_Unit__c = 'GCI', 
                                     X2016_Starting_Amount__c = 5, 
                                     BMS_Code__c = 'X1357', 
                                     License_Type__c = 'Service Cloud - Unlimited Edition', 
                                     Monthly_Unit_Price__c = 83.00, 
                                     Running_License_Total__c = 500, 
                                     Org__c = 'CRM Innovation', 
                                     License_Year__c = '2017');
        insert ln3;
        
         //create a license Record
        License_Numbers__c ln4 = new License_Numbers__c(
                                     Business_Unit__c = 'GCI', 
                                     X2016_Starting_Amount__c = 5, 
                                     BMS_Code__c = 'X1357', 
                                     License_Type__c = 'Analytics Cloud - Wave Analytics Platform', 
                                     Monthly_Unit_Price__c = 52.50, 
                                     Org__c = 'CRM Innovation', 
                                     License_Year__c = '2017');
        insert ln4;

}


}

 
  • October 12, 2016
  • Like
  • 0
I have some code iterating through a list according to who is logged in and it displays on the screen.  In this list, there is a subtotal and a total.  I'm wanting to get a total of all the subtotal items and a total of the total items.

How would I accomplish that?

Here's what I have, but the calculation is not working
aTotal.Annualized_Running_Total__c = aTotal.Annualized_Running_Total__c + a.X2016_Cost__c;  
public with sharing class LicenseList { 
private final License_Numbers__c ln; 
public user currentuser{get;set;} 
public id tobeEdited{get;set;}


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, Business_Unit__c, Annualized_Running_Total__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 License_Type__c];
 
        License_Numbers__c aTotal;
        for(License_Numbers__c a:lntypes16){
                //aTotal.Annualized_Running_Total__c = aTotal.Annualized_Running_Total__c + a.X2016_Cost__c;   
                break;
            }
        

return lntypes16; 
} 


//-----------------------------------------------------------------------------
public List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();

public List <License_Numbers__c> getLicenseList17(){ 

selectedTypes=[select id, Name, 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' ORDER BY License_Type__c]; 

return selectedTypes; 
} 
    public void saveRecord(){ 
    License_Numbers__c tobeupdated;
    for(License_Numbers__c temp:selectedTypes){
        if(temp.id==tobeEdited){
            tobeupdated = temp;
            break;
         }
     }
        update selectedTypes;
        tobeEdited = null;
    } 
}

 
  • October 05, 2016
  • Like
  • 0
I'm trying to write a trigger to make sure certain fields are not empty based on the status that is chosen.  I have several different types of fields I'm trying to validate.  My code is below but it doesn't seem to be validating anything

Resolution_Detail__c = RTF
Workaround_ICA__c = RTF
Defect_Type_Multi__c = multipicklist
Declined_Reason__c= picklist
NPI_Numbertext__c = plain text
NPI_Tracking_Link__c = URL
CPI_Numbertext__c = plain text
CPI_Tracking_Link__c = URL
Change_Numbertext__c = plain text
CPI_Tracking_Link__c = URL





 
trigger CWStatusValidation on Case (before update, before insert)
{

              
        for (Case objCase : Trigger.new)
        {
           //If Status is any of the following and Resolution Detail is empty, prompt to fill in.
           if((objCase.Status == 'Closed - Cancelled' || objCase.Status == 'Closed - Unable to Reproduce' || objCase.Status == 'Closed - Duplicate'
           || objCase.Status == 'Recurring Incident') && objCase.Resolution_Detail__c == '')            
           {
                trigger.new[0].addError('Please fill in the Resolution Detail for this case.');
           }
              //If Status is any of the following and ICA is empty, prompt to fill in.
              if((objCase.Status == 'Pending - RCA' || objCase.Status == 'Pending - Customer Validation' 
              || objCase.Status == 'Pending - Dealer Validation' || objCase.Status == 'Pending - Evaluation') && objCase.Workaround_ICA__c == '')             
              {
                trigger.new[0].addError('Please fill in the Workaround / ICA for this case.');
              }
                    //If Status = Pending - CPI, fill in Resolution Details, CPI Number and CPI Tracking Link
                    if(objCase.Status == 'Pending - CPI' && objCase.CPI_Numbertext__c == ' ' && objCase.CPI_Tracking_Link__c == ' ' && objCase.Resolution_Detail__c == '' )            
                    {
                        trigger.new[0].addError('Please fill in the Resolution Details, CPI Number and CPI Tracking Link for this case.');
                    }
                         //If the Status = Closed - Declined, fill in Resolution Detail, Defect Type and Declined Reason.
                         if(objCase.Status == 'Closed - Declined' && objCase.Resolution_Detail__c == '' && objCase.Defect_Type_Multi__c == '' && objCase.Declined_Reason__c == '')
                         {
                           trigger.new[0].addError('Please fill in the Resolution Details, Defect Type and Declined Reason for this case.');
                         }
                            //If the Status = Pending - NPI, fill in Resolution Detail, NPI Number and NPI Tracking Link.
                            if(objCase.Status == 'Pending - NPI' && objCase.Resolution_Detail__c == '' && objCase.NPI_Numbertext__c == null && objCase.NPI_Tracking_Link__c == null)
                            {
                               trigger.new[0].addError('Please fill in the Resolution Details, NPI Number and NPI Tracking Link for this case.');
                            }
                                //If the Status = Pending - Change, fill in Resolution Detail, Change Number and Change Tracking Link.
                                if(objCase.Status == 'Pending - Change' && objCase.Resolution_Detail__c == '' && objCase.Change_Number__c == '' && objCase.Change_Tracking_Link__c == '')
                                {
                                   trigger.new[0].addError('Please fill in the Resolution Details, Change Number and Change Tracking Link for this case.');
                                }
                                    //If the Status is any of the following, fill in Resolution Detail and Defect Type.
                                    if((objCase.Status == 'Closed - Resolved' || objCase.Status == 'Closed - No Response') && objCase.Resolution_Detail__c == '' && objCase.Defect_Type_Multi__c == '' )
                                    {
                                       trigger.new[0].addError('Please fill in the Resolution Details and Defect Type for this case.');
                                    }
           
         }       
}
  • November 24, 2014
  • Like
  • 1
I'm wanting a way to get a count of useful solution articles.  Is there a way to do this sort of thing in apex or something.  I have no idea where to begin.  Any help would be awesome!
  • April 10, 2014
  • Like
  • 1
I have history tracking set for a custom field called Button Clicked on a custom object Change.  I have the field being updated through a Propose a Change button.  If a Dealer portal user clicks the buttton, the history gets updated and last modified gets updated.  If a Customer Portal User clicks the button the history doesn't get updated and the last modified date doesn't get updated.  I can't for the life of me see a difference between the 2 profiles except for the fact they are 2 different licenses.  Any ideas?
  • April 02, 2014
  • Like
  • 1
I'm making an escalate case button for our customers to use.  I need the funtionality to assign the case to a generic support queue if a checkbox is true, if not I need it to assign the case to the corresponding partner queue, which are set in the case assignment rules.  Is there a way to invoke the assignment rules in the javascript button? 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 


if('{!Case.CW_Advance_Support_Needed__c}' == true) 
{ 
caseObj.OwnerId = '00G30000001oUSL'; 
caseObj.Status = 'In Progress'; 

}else{ 


caseObj.CW_Advance_Support_Needed__c='True'; 
caseObj.Escalated_Date_Time__c=new Date().toJSON(); 

} 

if('{!Case.Incident_First_Response__c}'=='') 
{ 
caseObj.Incident_First_Response__c=new Date().toJSON(); 
} 

var result = sforce.connection.update([caseObj]); 
window.location.href=window.location.href;
  • September 18, 2018
  • Like
  • 0
I have a test class that is 68% covered.  I have 2 lines throughout that I cannot get covered.  Can anyone help me get them covered?
Its the 2 lines after the else statement.  
 
if (oldCase.Substatus__c == 'Open with Cat Support') {
                                // Log into the "Open with Cat Support" bucket
                                if(c.Accumulated_Duration_Open_with_Cat_Supp__c != Null) {
                                  c.Accumulated_Duration_Open_with_Cat_Supp__c += elapsedHours;
                                }
                                else {
                                    c.Accumulated_Duration_Open_with_Cat_Supp__c = 0.0;
                                    c.Accumulated_Duration_Open_with_Cat_Supp__c += elapsedHours;
                                }
                            }

 
  • April 17, 2017
  • Like
  • 0
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>

 
  • March 16, 2017
  • Like
  • 0
I have the below method that I don't understand how to cover in my test class.  Can anyone help please?
 
@future
    public static void createLicenseGroups()
    {

        //Query for the Account record types
        List<RecordType> rtypes = [SELECT Name, Id FROM RecordType WHERE sObjectType='License__c' AND isActive=true];
     
        //Create a map between the Record Type Name and Id for easy retrieval
        Map<String,String> LicRecTyp = new Map<String,String>{};
        for(RecordType rt: rtypes)
           LicRecTyp.put(rt.Name,rt.Id);
           
        ID gID = LicRecTyp.get('License Group');

        List<License__c> licenseGroups = new List<License__c>();
        
        Map<STRING, Schema.sObjectField> fieldsMap = Schema.SObjectType.User.fields.getMap();
        for (Schema.PicklistEntry p : fieldsMap.get('SF_License_Owner_Type__c').getDescribe().getPicklistValues())   
            licenseGroups.add(new License__c(RecordTypeID = gID, Owner_Group_Name__c = p.getLabel(), Licenses_Owned__c = 9999, Licenses_Used__c = 0));    
        
        insert licenseGroups;
}

 
  • February 22, 2017
  • Like
  • 0
I have the following code.  Business_Unit_new__c in the User object is the multipicklist.  
I want to pull records from the License Numbers object where the Business Unit (picklist) from the License record is equal to the Business Unit of the current user (multipicklist).  The users may have more than 1 Business Unit assigned to them.

I've tried WHERE Business_Unit__c INCLUDES (:currentuser.Business_Unit_new__c) and it errors saying includes can only be used with a multipick list

If I try 
currentuser.Business_Unit_new__c INCLUDES (:Business_Unit__c) it errors saying it doesn't understand the relationship with currentuser.

How do I fix this?(this is not the complete code, jus tthe snipit that i need the query in)
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 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(); 

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 

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

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

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__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; 
}



 
  • November 02, 2016
  • Like
  • 0
I have the following code, the last section has fields to add more licenses to the list.  After Save, I'd like the fields to return to blank or None, or whatever they were before the use filled them in.  Right now, if I F5, it adds another license to the list.  If I try to change the values and click save it errors, and then adds the previous options to the list again.
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" showHeader="false" 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:pageBlock>
<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="Current 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="2016 Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Cost" value="{!ln.X2016_Cost__c}"/>

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

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>



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

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

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


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

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<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 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_Type__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="2017 Annualized Cost" value="{!ln17.X2017_Subtotal__c}" />

<apex:column headerValue="Estimated 2017 Cost" value="{!ln17.X2017_Cost__c}"/>


</apex:pageBlockTable>

</apex:pageBlock>

<!------------------------------------------------------------------------------------------>
<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_Type__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}" onclick=""/>
</apex:column>

</apex:pageBlockTable>


</apex:pageBlock>
<apex:commandButton value="Save" action="{!save}" />

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

        
</apex:form>

<!--------------------------------------------------------------------------------------------------------->
</apex:page>
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 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(); 

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 

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

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

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__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; 
} 


//-----------------------------------------------------------------------------
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, 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' 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; 
} 
    public void saveRecord(){ 
    License_Numbers__c tobeupdated;
    for(License_Numbers__c temp:selectedTypes){
        if(temp.id==tobeEdited){
            tobeupdated = temp;
            
         }
     }
        update selectedTypes;
        tobeEdited = null;
    } 
//--------------------------------------------------------------------------------------------    

public List<License_Numbers__c> addlic {get; set;} 
  
public PageReference save()
{
    List<License_Numbers__c> addlic=new List<License_Numbers__c>();
    for(AccountWrapper wrap:wrappers)
    {
       License_Numbers__c lic = wrap.lic;
       lic.RecordTypeID = '012Q00000009F7P';
       lic.License_Year__c = '2017';
       addlic.add(wrap.lic);
    }
        
    insert addlic;
    //addlic = null;
    
    return new PageReference('/apex/LicenseSummaryHomePage');
         
}

public class AccountWrapper
{
    public License_Numbers__c lic{get; private set;}
    public Integer ident{get; private set;}
    
    
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        lic=new License_Numbers__c();
            
    }
}  //There's a lot more code here for the Schedules part - doesn't pertain to my problem
}

User-added image
 
  • October 17, 2016
  • Like
  • 0
Can someone please explain (and possibly fix) why the last section on my VF Page falls out of the frame?  The other frames stay within the "page" but the last section falls off.  

User-added image
 
<apex:page standardController="License_Numbers__c" recordSetvar="lic" extensions="LicenseList" showHeader="false" 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:pageBlock>
<!---------------------------------------------------------------------------------------------------->
<apex:form >
<!--displays the licenses that are owned by your business unit (declared on User record)-->
<apex:pageBlock title="Current 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="2016 Annualized Cost" value="{!ln.X2016_Subtotal__c}" />
<apex:column headerValue="2016 Cost" value="{!ln.X2016_Cost__c}"/>

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

                
          
</apex:pageBlock>

</apex:form>

<apex:panelGrid columns="1">

</apex:panelGrid>



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

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

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


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

<apex:outputLink value="{!ln17.Id}">{!ln17.Name}</apex:outputLink>
<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 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_Type__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="2017 Annualized Cost" value="{!ln17.X2017_Subtotal__c}" />

<apex:column headerValue="Estimated 2017 Cost" value="{!ln17.X2017_Cost__c}"/>


</apex:pageBlockTable>

</apex:pageBlock>

<!------------------------------------------------------------------------------------------>
<apex:pageBlock title="New Licenses Needed for 2017">

<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="BMS Code">
<apex:inputField value="{!wrapper.lic.BMS_Code__c}" />
</apex:column>

<apex:column HeaderValue="License Type">
<apex:inputField value="{!wrapper.lic.License_Type__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="License Year">
<apex:inputField value="{!wrapper.lic.License_Year__c}" />
</apex:column>

</apex:pageBlockTable>


</apex:pageBlock>
<apex:commandButton value="Save" action="{!save}"/>


</apex:form>

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

 
  • October 13, 2016
  • Like
  • 0
I have a test class started, got the dummy data created and now I'm not sure where to go.

How do you write a test class for all this??  Can't SF create something that would automatically create the test class for you????
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 id tobeAdded{get;set;}
public List<AccountWrapper> wrappers{get;set;}
public static Integer addCount{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(); 

wrappers=new List<AccountWrapper>();
for(Integer idx=0; idx<1; idx++)
{
    wrappers.add(new AccountWrapper(nextIdent++));
}

} 

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

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

public List <License_Numbers__c> getLicenseList(){ 
lntypes16 = [select id, Name, X2016_Cost__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; 
} 


//-----------------------------------------------------------------------------
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, 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' 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; 
} 
    public void saveRecord(){ 
    License_Numbers__c tobeupdated;
    for(License_Numbers__c temp:selectedTypes){
        if(temp.id==tobeEdited){
            tobeupdated = temp;
            
         }
     }
        update selectedTypes;
        tobeEdited = null;
    } 
//--------------------------------------------------------------------------------------------    

public List<License_Numbers__c> addlic {get; set;} 
  
public PageReference save()
{
    List<License_Numbers__c> addlic=new List<License_Numbers__c>();
    for(AccountWrapper wrap:wrappers)
    {
        addlic.add(wrap.lic);
    }
    insert addlic;
    
    return new PageReference('/apex/LicenseSummaryHomePage');
}

public class AccountWrapper
{
    public License_Numbers__c lic{get; private set;}
    public Integer ident{get; private set;}
    
    public AccountWrapper(Integer inIdent)
    {
        ident=inIdent;
        lic=new License_Numbers__c();
    }
}   

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

public SelectOption[] getSchedules() {
        return new SelectOption[] { 
            new SelectOption('Value0', '--None--'),
            new SelectOption('Value1', 'Value1'),
            new SelectOption('Value2', 'Value2'), 

  };

    }
public String discountScheduleID { get; set; }

//--------------------------------------------------------------
 Public string OutPutString{get;set;}
 Public String SelectOption;
public void displayDescription(){
if (discountScheduleID == 'Value1')
{
OutPutString = 'No Description Available' ;
}else if (discountScheduleID == 'Value2')
    {
        OutPutString = 'No Description Available' ;
}}





 
@isTest 
private class LicenseListTest{
   
   static testMethod void LicenseListTest(){
        Profile p = [SELECT Id FROM Profile WHERE Name='Community Super User' limit 1]; 
        //create a user
        UserRole r = [SELECT Id FROM userrole WHERE name = 'CM User' limit 1];
        
        User u1 = new User(LastName = 'Test Class',
                                    Username = 'CRMUser@Test.com',
                                    UserRoleId = r.Id,
                                    Email = 'CRMUser@Test.com',
                                    Alias = 'tclass',
                                    CommunityNickname = 'tclass',
                                    TimeZoneSidKey = 'Asia/Kolkata',
                                    LocaleSidKey = 'en_US',
                                    EmailEncodingKey = 'UTF-8', 
                                    ProfileId = p.Id,
                                    LanguageLocaleKey = 'en_US',
                                    Business_Unit__c = 'GCI');
        insert u1;

}
static testMethod void LicenseList_test() {

//create a license Record
        License_Numbers__c ln1 = new License_Numbers__c(
                                     Business_Unit__c = 'GCI', 
                                     X2016_Starting_Amount__c = 5, 
                                     BMS_Code__c = 'X1357', 
                                     License_Type__c = 'Service Cloud - Unlimited Edition', 
                                     Monthly_Unit_Price__c = 83.00, 
                                     Running_License_Total__c = 500, 
                                     Org__c = 'CRM Innovation', 
                                     License_Year__c = '2016');
        insert ln1;
        
         //create a license Record
        License_Numbers__c ln2 = new License_Numbers__c(
                                     Business_Unit__c = 'GCI', 
                                     X2016_Starting_Amount__c = 5, 
                                     BMS_Code__c = 'X1357', 
                                     License_Type__c = 'Analytics Cloud - Wave Analytics Platform', 
                                     Monthly_Unit_Price__c = 52.50, 
                                     Org__c = 'CRM Innovation', 
                                     License_Year__c = '2016');
        insert ln2;
}



static testMethod void LicenseList17_test() {
//create a license Record
        License_Numbers__c ln3 = new License_Numbers__c(
                                     Business_Unit__c = 'GCI', 
                                     X2016_Starting_Amount__c = 5, 
                                     BMS_Code__c = 'X1357', 
                                     License_Type__c = 'Service Cloud - Unlimited Edition', 
                                     Monthly_Unit_Price__c = 83.00, 
                                     Running_License_Total__c = 500, 
                                     Org__c = 'CRM Innovation', 
                                     License_Year__c = '2017');
        insert ln3;
        
         //create a license Record
        License_Numbers__c ln4 = new License_Numbers__c(
                                     Business_Unit__c = 'GCI', 
                                     X2016_Starting_Amount__c = 5, 
                                     BMS_Code__c = 'X1357', 
                                     License_Type__c = 'Analytics Cloud - Wave Analytics Platform', 
                                     Monthly_Unit_Price__c = 52.50, 
                                     Org__c = 'CRM Innovation', 
                                     License_Year__c = '2017');
        insert ln4;

}


}

 
  • October 12, 2016
  • Like
  • 0
public class wrapperClassController {
    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class lntypes {
        public License_Numbers__c con {get; set;}
        public Boolean tobeEdited {get; set;}

        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public lntypes(License_Numbers__c c) {
            con = c;
            tobeEdited = false;
        }
    }
        
    //Our collection of the class/wrapper objects cContact
    public List<lntypes> licList {get; set;}

    //This method uses a simple SOQL query to return a List of Contacts
    public List<lntypes> getLicenseList17() {
        if(licList == null) {
            licList = new List<lntypes>();
            for(License_Numbers__c c:[select id, Name, X2016_Cost__c, Business_Unit__c, X2016_Starting_Amount__c, X2016_Subtotal__c, BMS_Code__c, License_Type__c, Monthly_Unit_Price__c, Org__c FROM License_Numbers__c ]) {

                // As each contact is processed we create a new cContact object and add it to the contactList
                licList.add(new lntypes(c));
            }
        }
        return licList;
    }
    public PageReference saveRecord() {

        //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<License_Numbers__c> selectedTypes = new List<License_Numbers__c>();

        //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
        for(lntypes cCon: getLicenseList17()) {
            if(cCon.tobeEdited == true) {
                selectedTypes.add(cCon.con);
            }
        }

        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
        System.debug('These are the selected Contacts...');
        for(License_Numbers__c con: selectedTypes) {
            system.debug(con);
        }
        contactList=null; // we need this line if we performed a write operation  because getContacts gets a fresh list now
        return null;
    }

    
}
I have a wrapper class that is suppose to loop through some license records and then if one is edited to update it.  

Just copying the wrapper class from SFCD and changing the variable to match what I need I'm getting a unexpected token 'class'  at line 70 column 11

Line 70
public class lntypes {

What is my problem?
 
  • September 21, 2016
  • Like
  • 0

I'm not sure how to accomplish this.  I have a javascript button Reject, but if someone decides to cancel rejecting the record, the Status still get changed to Rejected.  Where do I move the update code so that if they click Cancel on the Edit screen the Status won't change?

 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 
{!requireScript("/soap/ajax/20.0/apex.js")} 

var changeObj = new sforce.SObject("Change__c");
changeObj.Id = '{!Change__c.Id}';

var profileName = '{!$Profile.Name}';
var roleName = '{!$UserRole.Name}';

var d=new Date().toISOString();;
/*var n=d.toJSON();*/

if(changeObj.StatusChange__c='Proposed')
{ 

//If current user’s profile is CW Pilot Dealer Portal User and Contact has accepted or Contact is a Dealer Portal User
if((profileName.indexOf("Dealer")!=-1)&&('{!Change__c.Contact_Accepted__c}'==true))
{
changeObj.Dealer_Rejected__c='{!$User.FirstName}'+' {!$User.LastName}';
changeObj.Dealer_Rejected_Checkbox__c= true; //check the box 
/*changeObj.Dealer_Rejected_Date_Time__c="changeObj.Dealer_Rejected_Date_Time__c";*/
changeObj.Dealer_Rejected_Date_Time__c=d;
changeObj.StatusChange__c='Rejected';

window.parent.location='/apex/rejectChangeDealer?Id={!Change__c.Id}&retURL=/{!Change__c.Id}';

}else{

//If current user's profile is CW Pilot Dealer Portal User and Contact Accepted is not checked, throw an error 
if((profileName.indexOf("Dealer")!=-1)&&('{!Change__c.Contact_Accepted__c}' != true))
{ 
alert("Additional approvals/rejections are required before you can perform this action.");
}else{

//If current users profile is Customer Portal, fill in the current users name for Contact Rejected and fill in the current date and time 
if(profileName.indexOf("Customer")!=-1)
{
changeObj.Contact_Rejected__c='{!$User.FirstName}'+' {!$User.LastName}';
changeObj.Contact_Rejected_Checkbox__c= true;
/*changeObj.Contact_Rejected_Date_Time__c="changeObj.Contact_Rejected_Date_Time__c";*/
changeObj.Contact_Rejected_Date_Time__c=d;
changeObj.StatusChange__c='Rejected';
alert("You have selected to reject this change.  Please fill in the Contact Rejected Comments in the Rejected Information section towards the bottom this Change record.")
window.parent.location.href="/{!Change__c.Id}" + "/e"; 

}else{

if((roleName.indexOf("Tier 2") != -1) || (roleName.indexOf("Product Support Manager") != -1)) 
{
if(('{!Change__c.Contact_Accepted__c}'==true) && ('{!Change__c.Dealer_Accepted__c}'==true))
{
changeObj.Change_Manager_Rejected__c='{!$User.FirstName}'+' {!$User.LastName}';
changeObj.Change_Manager_Rejected_Checkbox__c=true;
/*changeObj.Change_Manager_Rejected_Date_Time__c="changeObj.Change_Manager_Rejected_Date_Time__c";*/
changeObj.Change_Manager_Rejected_Date_Time__c=d;
changeObj.StatusChange__c='Rejected';
window.parent.location='/apex/rejectChangeChgMgr?Id={!Change__c.Id}&retURL=/{!Change__c.Id}';
}else{
alert("Additional approvals/rejections are required before you can perform this action.");
}
}else{
alert("You are not authorized to perform this action.");
}}}}
}else{
alert("Status needs to be Planned before you approve of this change.");
}

if(changeObj.StatusChange__c == 'Approved')
{
alert("Change has already been Approved.");
}else{

if((changeObj.StatusChange__c=='Implemented') || (changeObj.StatusChange__c=='Completed'))
{
alert("Change has already been Implemented. Approvals are no longer needed.");
}}

var result = sforce.connection.update([changeObj]);
if (result[0].success=='false')
{
alert(result[0].errors.message);
}

 

  • August 26, 2013
  • Like
  • 0