• Collen Mayer 6
  • NEWBIE
  • 120 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 25
    Questions
  • 27
    Replies
On my page, I've got a table of rows.  At the bottom of the table I have an "Add Row" button, which works fine.  Each row has a "Delete" button, which should remove the row on the page immediately, and delete it from the database on "Save."  At the first delete, the page re-renders successfully.  However, the delete functionality begins acting very strange if I try to delete two rows (on the second "click" of a delete button) before saving; sometimes the wrong row is deleted from the page, and then a different row is deleted from the table.  I've tried every form of debugging I can, but cannot figure out what's going on.  I suspect it has something to do with a counter getting off with the second delete, but I'm not sure.  I'd really appreciate somebody giving thoughts on what I'm doing wrong.  

Extension:
 
public with sharing class PayrollAuthorization_extn {
   
    public list <PA_Distribution__c> PayrollDistributionList {get; set;}
    public Payroll_Authorization__c PA;
    public PA_Distribution__c del;
     public String rowID {get;set;}
    public List<PA_Distribution__c> delProgramList {get; set;}
 
    
    public PayrollAuthorization_extn(ApexPages.StandardController controller) {
        
      PA = (Payroll_Authorization__c)controller.getRecord();
      PayrollDistributionList = [Select Id, Name, Program__r.Name, Program_Percent__c, Program_as_Number__c
             From PA_Distribution__c
              Where Payroll_Authorization__r.id =: controller.getId()
            ];  
    delProgramList = new List<PA_Distribution__c>();            
    }
    
    public void addRow(){
         PayrollDistributionList.add(new PA_Distribution__c(    Payroll_Authorization__c = PA.id));
    }
    
    public PageReference SavePA (){
        upsert PA;
        upsert PayrollDistributionList;
        System.debug ('Upsert:' + PayrollDistributionList);
        delete delProgramList;
        System.debug ('Delete:' + delProgramList);
        return (new ApexPages.StandardController(PA)).view();
    }
    
    public void deleteRow(){
        

        rowID =ApexPages.currentPage().getParameters().get('RowID');
        
        For (Integer i=0; i<PayrollDistributionList.size(); i++){
        del= PayrollDistributionList[i];
            If (del.Id == rowID) {
                
                System.debug('Delete index: ' + i +  PayrollDistributionList[i]);
                PayrollDistributionList.remove(i);
                System.debug('List remaining is ' + PayrollDistributionList );
                
                If(del.Id <> null) delProgramList.add(del);
                System.debug ('Detele these: ' + delProgramList);
                break;
            }
            
        }
       }
    
}



My page:

      
<apex:page standardController="Payroll_Authorization__c" sidebar="false" doctype="html-5.0" standardStylesheets="false" extensions="PayrollAuthorization_extn" applyBodyTag="true" lightningStylesheets="true">
    <head>
      <meta charset="utf-8"/>
      <meta name="viewport" content="width=device-width, initial-scale=1"/>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <style>
          .form-control {
              padding: 6px !important;
          }
          .btn-info {
            color: #fff!important;
            background-color: #5bc0de !important;
            border-color: #46b8da !important;
            background-image: none !important;
            padding: 8px 20px !important;
        }
         .table>thead>tr>th{
                vertical-align: top !important;
                text-align: left !important;
          }
          .table>tbody>tr>td{
                vertical-align: top !important;
                text-align: left !important;
          }
          .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
                padding: 4px !important;
            }
            .list-group-item {
                padding: 6px 15px !important;
            }
      </style>
    <apex:outputPanel id="scriptPanel">
        <script>
              
        function calctotal(){
            //   alert ("caltotal" + {!PayrollDistributionList.size});
              var tempRowTotal=0;
              var percenttotal= 0;
            for(var i=1; i<={!PayrollDistributionList.size};i++ ){
                  
                  tempRowTotal = ($('.wh'+i).val()!= null && $('.wh'+i).val() != '')?parseFloat($('.wh'+i).val()):0.0;
                  percenttotal  += tempRowTotal;
                  
                  }
            return percenttotal;   
        }
          
        function calcRow(){
            //   alert ("calrow");
              
            var tempRowTotal=0;
             var percenttotal= 0;
               percenttotal= calctotal();
             for(var i=1; i<={!PayrollDistributionList.size};i++ ){    
              tempRowTotal = ($('.wh'+i).val()!= null && $('.wh'+i).val() != '')?parseFloat($('.wh'+i).val()):0.0;
              $('.wp' + i).text(((tempRowTotal * 100)/percenttotal).toFixed(2)+'%');
              $('.percenttotal').text(percenttotal.toFixed(2)+'%');        
              }
          }
            $(document).ready(function(){
                  {
                      calcRow();
                   }
    
          });    
    
        </script>
       </apex:outputPanel>
        <script>
    
        </script>
        </head>
    <body>
        <apex:form >
            <apex:pageBlock title="Payroll Distribution" id="er" >
            <div align="center" draggable="false" style="font-size:13px; margin-bottom:4px"  >
                <apex:commandButton value="Save" action="{!SavePA}" styleclass="btn btn-info" style="" />&nbsp;&nbsp;
                <apex:commandButton value="Cancel" action="{!Cancel}" styleclass="btn btn-info" immediate="true"/>
            </div>
            <div class="container-flud" style="font-size: 11.5px;">
                <apex:pageMessages ></apex:pageMessages>
                <div class="col-md-12" style="margin-bottom: -15px;">
                    <ul class="list-group">      
                        <li class="list-group-item row" style="background-color: #702342;color: #fff;padding: 6px 10px;">
                            <h4 style="margin: 2px 0px;font-size: 12px;font-weight: bolder;">Payroll Authorization</h4>
                        </li>
                    </ul>
    
          <div class="col-md-12" style="margin-bottom: 15px;">
            <ul class="list-group">      
                <li class="list-group-item row" style="background-color: #702342;color: #fff;padding: 6px 10px;">
                    <h4 style="margin: 2px 0px;font-size: 12px;font-weight: bolder;">Payroll Distributions</h4>
                </li>
            </ul>
            </div>
        <table class="table table-bordered" >
                       
                    <thead>
                    <tr>
                        <th>
                            Action
                        </th>    
                        <th>
                            Program
                        </th>
                        <th>
                            Percentage worked
                        </th>
                        <th>
                            Percentage total
                        </th>
                      </tr>
                    </thead>
                    <tbody>
                        <apex:variable var="SelectedRowId" value="{!0}"/>
                        <apex:variable value="{!1}" var="index"/>  
                    <apex:repeat value="{!PayrollDistributionList}" var="pd">
                        <tr>
                            <td>
                                <apex:commandButton value="Delete" action="{!deleteRow}" immediate="true" reRender="er, scriptPanel" >
                                     <apex:param name="RowID" value="{!pd.ID}"/>
                                  </apex:commandButton>
                            </td>
                            <td><apex:inputfield value="{!pd.Program__c}"   style="Width: 50%"/></td>
                            <td ><apex:inputfield value="{!pd.Program_Percent__c}" styleClass="wh{!index}" onkeyup="calcRow()"/> </td>
                            <td Class="wp{!index}">
                                0%
                            </td>
                        </tr>
                        <apex:variable value="{!index+1}" var="index"/>
                       
                    </apex:repeat>
                </tbody>
            <tfoot> <tr>
                <th/>
                <th/>
                    <th class="percenttotal">
                        0.0%
                    </th>
                    <th>
                        100.00%
                    </th>
                  </tr></tfoot>
              </table>
              </div>
               </div>
        <apex:commandButton action="{!addRow}" value="Add Program" immediate="true" reRender="er, scriptPanel"/>
            </apex:pageBlock>
            </apex:form>
        
        </body>
    </apex:page>

 
I've got a visualforce page with javascript formulas totaling records at the bottom.  I've recently added the ability to add a row to the page by clicking a button.  However the size of my list (!PayrollDistributionList.size) is not increasing when I do that (unless I "save" and refresh the page), so my column total ends up incorrect, and it doesn't iterate over all the rows.   Can someone provide some guidance?

My page:
<apex:page standardController="Payroll_Authorization__c" sidebar="false" doctype="html-5.0" standardStylesheets="false" extensions="PayrollAuthorization_extn" applyBodyTag="true" lightningStylesheets="true">
<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
      .form-control {
          padding: 6px !important;
      }
      .btn-info {
        color: #fff!important;
        background-color: #5bc0de !important;
        border-color: #46b8da !important;
        background-image: none !important;
        padding: 8px 20px !important;
    }
     .table>thead>tr>th{
            vertical-align: top !important;
            text-align: left !important;
      }
      .table>tbody>tr>td{
            vertical-align: top !important;
            text-align: left !important;
      }
      .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
            padding: 4px !important;
        }
        .list-group-item {
            padding: 6px 15px !important;
        }
  </style>
	<script>
	      
    function calctotal(){
          alert ("caltotal" + {!PayrollDistributionList.size}); 
          var tempRowTotal=0;
          var percenttotal= 0;
        for(var i=1; i<={!PayrollDistributionList.size};i++ ){
              
              tempRowTotal = ($('.wh'+i).val()!= null && $('.wh'+i).val() != '')?parseFloat($('.wh'+i).val()):0.0;
              percenttotal  += tempRowTotal;
              
          	}
        return percenttotal;   
    }
      
    function calcRow(){
          alert ("calrow"); 
          
        var tempRowTotal=0;
         var percenttotal= 0;
           percenttotal= calctotal(); 
 		for(var i=1; i<={!PayrollDistributionList.size};i++ ){	
          tempRowTotal = ($('.wh'+i).val()!= null && $('.wh'+i).val() != '')?parseFloat($('.wh'+i).val()):0.0;
          $('.wp' + i).text(((tempRowTotal * 100)/percenttotal).toFixed(2)+'%');
          $('.percenttotal').text(percenttotal.toFixed(2)+'%');		
          }
      }
    
    $(document).ready(function(){
              {
                  calcRow();
         	  }

      });
    </script>
    </head>
<body>
	<apex:form >
        <apex:pageBlock title="Payroll Distribution" id="er" >
		<div align="center" draggable="false" style="font-size:13px; margin-bottom:4px"  >
    		<apex:commandButton value="Save" action="{!SavePA}" styleclass="btn btn-info" style="" />&nbsp;&nbsp;
    		<apex:commandButton value="Cancel" action="{!Cancel}" styleclass="btn btn-info" immediate="true"/>
		</div>
		<div class="container-flud" style="font-size: 11.5px;">
    		<apex:pageMessages ></apex:pageMessages>
    		<div class="col-md-12" style="margin-bottom: -15px;">
        		<ul class="list-group">      
            		<li class="list-group-item row" style="background-color: #702342;color: #fff;padding: 6px 10px;">
                		<h4 style="margin: 2px 0px;font-size: 12px;font-weight: bolder;">Payroll Authorization</h4>
            		</li>
        		</ul>

      <div class="col-md-12" style="margin-bottom: 15px;">
        <ul class="list-group">      
            <li class="list-group-item row" style="background-color: #702342;color: #fff;padding: 6px 10px;">
                <h4 style="margin: 2px 0px;font-size: 12px;font-weight: bolder;">Payroll Distributions</h4>
            </li>
        </ul>
    	</div>
	<table class="table table-bordered" >
                   
                <thead>
                <tr>
                <th>
                    Program
                </th>
                <th>
                    Percentage worked
                </th>
                <th>
                	Percentage total
                </th>
              </tr>
                </thead>
                <tbody>
                    <apex:variable value="{!1}" var="index"/>  
                <apex:repeat value="{!PayrollDistributionList}" var="pd">
                    <tr>
                        <td><apex:inputfield value="{!pd.Program__c}"   style="Width: 50%"/></td>
                        <td ><apex:inputfield value="{!pd.Program_Percent__c}" styleClass="wh{!index}" onkeyup="calcRow()"/> </td>
                    	<td Class="wp{!index}">
                    		0%
                		</td>
                    </tr>
                    <apex:variable value="{!index+1}" var="index"/>
                   
                </apex:repeat>
    		</tbody>
        <tfoot> <tr>
                <th>
                </th>
                <th class="percenttotal">
                    0.0%
                </th>
                <th>
                	100.00%
                </th>
              </tr></tfoot>
          </table>
          </div>
   		</div>
    <apex:commandButton action="{!addRow}" value="Add Program" immediate="true" reRender="er"/>
        </apex:pageBlock>
        </apex:form>
    
    </body>
</apex:page>
My extension: 
 
public with sharing class PayrollAuthorization_extn {
   
    public list <PA_Distribution__c> PayrollDistributionList {get; set;}
    public Payroll_Authorization__c PA;
    
    
    public PayrollAuthorization_extn(ApexPages.StandardController controller) {
        
  	PA = (Payroll_Authorization__c)controller.getRecord();
  	PayrollDistributionList = [Select Id, Name, Program__r.Name, Program_Percent__c
 			From PA_Distribution__c
      		Where Payroll_Authorization__r.id =: controller.getId()];  
                
    }
    
    public void addRow(){
 		PayrollDistributionList.add(new PA_Distribution__c(	Payroll_Authorization__c = PA.id));
	}
    
    public void SavePA (){
        upsert PA; 
        upsert PayrollDistributionList;
    }
    
    
}


 
HI All,
I need a solution to run an auto-launched visualwork flow on the first day of each month.  Would this be possible with Apex Scheduler?  Would anyone have any sample code of launching a flow from apex scheduler to help get me started (I've never worked wtih Apex Scheduler before)?

Thanks,
Collen. 
Greetings all,
I'm working on a test class and can't figure out why when I run the test I am not getting inside the for loop.  (I assume the test record I'm creating doesn't meet the criteria but can't figure out why).  Could someone kindly help me troubleshoot?  Thanks in advance!

Test class:
@istest
public class TestClassforInvoice {
 public static testMethod void testmyInvoices(){
	Account testAccount = new Account (Name = 'MyHousehold');
    Insert testAccount; 
    Contact testContact = new Contact (LastName= 'smith');
    insert testContact;
    AECaseMgmt__Program__c programNew = new AECaseMgmt__Program__c(Name= 'test prg'); 
	insert programNew; 
    AECaseMgmt__Program_Case__c testCase = new 	AECaseMgmt__Program_Case__c 
        (AECaseMgmt__Open_Date__c = System.now().date(), 	
         Program__c = programNew.Id, BypassValidationForProcessBuilder__c = true); 
     testCase.AECaseMgmt__Household__c = testAccount.id; 
    insert testCase;
    Case_Member_Enrollments__c testmember = new 
        Case_Member_Enrollments__c (Name = 'testCM', Case_ID__c = testCase.id, BypassValidationForProcessBuilder__c=true );
    
    testmember.Case_Member__c = testContact.id;
     insert testmember; 
    
     Client_Billing__c clientbill = new Client_Billing__c 
         (Entry_Type__c = 'Billed Expense', Billing_Item__c = 'Court Report', Client_Case__c = testCase.Id);
     
     PageReference pageRef = Page.SingleInvoice;
        Test.setCurrentPage(pageRef);
     ApexPages.StandardController sc = new ApexPages.StandardController(testcase);
		Invoice  controller = new Invoice(sc);
     pageRef = Page.MultipleInvoices;
        Test.setCurrentPage(pageRef);
		controller = new Invoice(sc);

 }
}
The for loop in my controller extension:

            for (AECaseMgmt__Program_Case__c  record: [Select ID, AECaseMgmt__Household__r.BillingSTreet, AECaseMgmt__Household__r.BillingCity,
                                                   AECaseMgmt__Household__r.BillingState,AECaseMgmt__Household__r.BillingPostalCode,
                                                   AECaseMgmt__Household__r.npe01__One2OneContact__r.name,
                                                   Program__r.name, Name,Account_Balance__c from  AECaseMgmt__Program_Case__c
                                                   where Id IN (SELECT Client_Case__c FROM Client_Billing__c)])  
            {
                caselist.add(New CasewInvoices (record));    
            }


Again, when I run the test, I'm not covering inside the for loop, and since "caselist" is not being populated, I'm not able to cover a large amount of the rest of my code.

And the entire controller:
public class Invoice {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public list <CasewInvoices> caselist {get; set;}
    public list <Client_Billing__c> tempinvoicelist {get; set;}
    public String currentRecordId {get;set;}
    public decimal thirtydayold {get; set;}
    public decimal sixtydayold {get;set;}
    public decimal ninetydayold {get;set;}
    
    public Invoice(ApexPages.StandardController controller) {
        stdCntrlr = controller;
        if (caselist==null){
            caselist = new List <CasewInvoices>();
            }
        
        tempinvoicelist = [Select ID, Client_Case__c, Name, Amount__c, Date__c,Transaction_Description__c, Amount_Credit_Debit__c 
                           from Client_Billing__c Where Include_on_Invoice__c = true ]; 
		currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');      
     	
        String pageName = ApexPages.currentPage().getUrl().substringAfter('apex/');
		system.debug('-----current ID name----'+currentRecordID);

// populate case list; if from single invoice, just get one case; otherwise get all        
        
            for (AECaseMgmt__Program_Case__c  record: [Select ID, AECaseMgmt__Household__r.BillingSTreet, AECaseMgmt__Household__r.BillingCity,
                                                   AECaseMgmt__Household__r.BillingState,AECaseMgmt__Household__r.BillingPostalCode,
                                                   AECaseMgmt__Household__r.npe01__One2OneContact__r.name,
                                                   Program__r.name, Name,Account_Balance__c from  AECaseMgmt__Program_Case__c 
                                                   where Id IN (SELECT Client_Case__c FROM Client_Billing__c)])  
        	{
            	caselist.add(New CasewInvoices (record));	
        	}
        
        
        for (CasewInvoices caseincrement:caselist)
        {
            Decimal thirtydayold = 3;
            for(Integer i = 0; i <tempinvoicelist.size(); i++){
            	if (tempinvoicelist[i].client_case__c ==caseincrement.clientcase.id)
                    {
                        caseincrement.billinglist.add (tempinvoicelist[i]);
                        If (tempinvoicelist[i].Amount_Credit_Debit__c>0)
                        {
                        	If (tempinvoicelist[i].date__c.daysBetween(date.today())> 90)
                        		caseincrement.ninetydayold = caseincrement.thirtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                        
                            If (tempinvoicelist[i].date__c.daysBetween(date.today())> 60)
                        		caseincrement.sixtydayold = caseincrement.thirtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                        
                            If (tempinvoicelist[i].date__c.daysBetween(date.today())> 30)
                        		caseincrement.thirtydayold = caseincrement.thirtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                        }
                        Else 
                        {
                            caseincrement.ninetydayold = caseincrement.ninetydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                            caseincrement.sixtydayold = caseincrement.sixtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                            caseincrement.thirtydayold = caseincrement.thirtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                        }
                    }
            }
        }
 }

	Public class CasewInvoices
    {
        public List<Client_Billing__c> billingList {get;set;}
        public AECaseMgmt__Program_Case__c Clientcase {get;set;}
        public decimal thirtydayold {get;set;}
        public decimal sixtydayold {get;set;}
        public decimal ninetydayold {get;set;}
        
        public CasewInvoices (AECaseMgmt__Program_Case__c cc)
        {
            Clientcase = cc;
            billingList = new list<Client_Billing__c>();
            thirtydayold = 0;
            sixtydayold = 0;
            ninetydayold = 0;
        }
	}
}
Hi All,
I'm getting an error when trying to write my test class for my controller extension: 

System.NullPointerException: Attempt to de-reference a null object//Class.Invoice.<init>: line 20, column 1
Class.TestClassforInvoice.testmyInvoices: line 25, column 1


Here's my test class:
@istest
public class TestClassforInvoice {
 public static testMethod void testmyInvoices(){
	Account testAccount = new Account (Name = 'MyHousehold');
    Insert testAccount; 
    Contact testContact = new Contact (LastName= 'smith');
    insert testContact;
    AECaseMgmt__Program__c programNew = new AECaseMgmt__Program__c(Name= 'test prg'); 
	insert programNew; 
    AECaseMgmt__Program_Case__c testCase = new 	AECaseMgmt__Program_Case__c 
        (AECaseMgmt__Open_Date__c = System.now().date(), 	
         Program__c = programNew.Id, BypassValidationForProcessBuilder__c = true); 
     testCase.AECaseMgmt__Household__c = testAccount.id; 
    insert testCase;
    Case_Member_Enrollments__c testmember = new 
        Case_Member_Enrollments__c (Name = 'testCM', Case_ID__c = testCase.id, BypassValidationForProcessBuilder__c=true );
    
    testmember.Case_Member__c = testContact.id;
     insert testmember; 
    
     Client_Billing__c clientbill = new Client_Billing__c 
         (Entry_Type__c = 'Planned Expense', Billing_Item__c = 'Court Report', Client_Case__c = testCase.Id);
     
     ApexPages.StandardController sc = new ApexPages.StandardController(testcase);
		Invoice  controller = new Invoice(sc);

		PageReference pageRef = Page.SingleInvoice;
        Test.setCurrentPage(pageRef);

 }
}
The problem seems to be here: 

ApexPages.StandardController sc = new ApexPages.StandardController(testcase); Invoice controller = new Invoice(sc);

This is my extension:
 
public class Invoice {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public list <CasewInvoices> caselist {get; set;}
    public list <Client_Billing__c> tempinvoicelist {get; set;}
    public String currentRecordId {get;set;}
    public decimal thirtydayold {get; set;}
    public decimal sixtydayold {get;set;}
    public decimal ninetydayold {get;set;}
    
    public Invoice(ApexPages.StandardController controller) {
        stdCntrlr = controller;
        if (caselist==null){
            caselist = new List <CasewInvoices>();
            }
        
        tempinvoicelist = [Select ID, Client_Case__c, Name, Amount__c, Date__c,Transaction_Description__c, Amount_Credit_Debit__c 
                           from Client_Billing__c Where Include_on_Invoice__c = true ]; 
		currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');      
     	
        String pageName = ApexPages.currentPage().getUrl().substringAfter('apex/');
		system.debug('-----current page name----'+pagename);

// populate case list; if from single invoice, just get one case; otherwise get all        
        
        If (pageName.contains('SingleInvoice'))
        {
        	for (AECaseMgmt__Program_Case__c  record: [Select ID, AECaseMgmt__Household__r.BillingSTreet, AECaseMgmt__Household__r.BillingCity,
                                                   AECaseMgmt__Household__r.BillingState,AECaseMgmt__Household__r.BillingPostalCode,
                                                   AECaseMgmt__Household__r.npe01__One2OneContact__r.name,
                                                   Program__r.name, Name,Account_Balance__c from  AECaseMgmt__Program_Case__c 
                                                   where Id =: currentRecordId])  
        	{
           		 caselist.add(New CasewInvoices (record));
        	}
        }
		Else
        {
            for (AECaseMgmt__Program_Case__c  record: [Select ID, AECaseMgmt__Household__r.BillingSTreet, AECaseMgmt__Household__r.BillingCity,
                                                   AECaseMgmt__Household__r.BillingState,AECaseMgmt__Household__r.BillingPostalCode,
                                                   AECaseMgmt__Household__r.npe01__One2OneContact__r.name,
                                                   Program__r.name, Name,Account_Balance__c from  AECaseMgmt__Program_Case__c  where Id IN (SELECT Client_Case__c FROM Client_Billing__c)])  
        	{
            	caselist.add(New CasewInvoices (record));	
        	}
        }
        
        for (CasewInvoices caseincrement:caselist)
        {
            Decimal thirtydayold = 3;
            for(Integer i = 0; i <tempinvoicelist.size(); i++){
            	if (tempinvoicelist[i].client_case__c ==caseincrement.clientcase.id)
                    {
                        caseincrement.billinglist.add (tempinvoicelist[i]);
                        If (tempinvoicelist[i].Amount_Credit_Debit__c>0)
                        {
                        	If (tempinvoicelist[i].date__c.daysBetween(date.today())> 90)
                        		caseincrement.ninetydayold = caseincrement.thirtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                        
                            If (tempinvoicelist[i].date__c.daysBetween(date.today())> 60)
                        		caseincrement.sixtydayold = caseincrement.thirtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                        
                            If (tempinvoicelist[i].date__c.daysBetween(date.today())> 30)
                        		caseincrement.thirtydayold = caseincrement.thirtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                        }
                        Else 
                        {
                            caseincrement.ninetydayold = caseincrement.ninetydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                            caseincrement.sixtydayold = caseincrement.sixtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                            caseincrement.thirtydayold = caseincrement.thirtydayold + tempinvoicelist[i].Amount_Credit_Debit__c;
                        }
                    }
            }
        }

 }

	Public class CasewInvoices
    {
        public List<Client_Billing__c> billingList {get;set;}
        public AECaseMgmt__Program_Case__c Clientcase {get;set;}
        public decimal thirtydayold {get;set;}
        public decimal sixtydayold {get;set;}
        public decimal ninetydayold {get;set;}
        
        public CasewInvoices (AECaseMgmt__Program_Case__c cc)
        {
            Clientcase = cc;
            billingList = new list<Client_Billing__c>();
            thirtydayold = 0;
            sixtydayold = 0;
            ninetydayold = 0;
        }
	}
}
Can someone help me troubleshoot this error, please?  Many thanks.

Collen

 
Hi All,
I'm need to pass a recordtype id from a visualforce page to my controller extension.  However debug log is showing the variable in the controller I'm trying to set is NULL (not getting the value from the visualforce page).  Here's what I've tried.  Any help/feedback would be greatly appreciated.  
Best,
Collen 

My test page: 
 
<apex:page standardController="Satisfaction_Surveys__c" extensions="CreateSatisfactionSurvey2">  
  <apex:sectionHeader title="Satisfaction Survey" subtitle="Please rate the service you receieved."/>

  <apex:form >
     
    <apex:pageMessages /> 
    <apex:pageBlock title="Survey Response">
        

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

      <apex:pageBlockSection showHeader="false" columns="2">
          <apex:inputField value="{!survey.Access_Comm_Resources__c}" />
      <apex:param assignTo="{!recordtypetext}" value="01236000000xk08" name="recordtypetext"/> 

        </apex:pageBlockSection>

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

My controller:
 
public  class CreateSatisfactionSurvey2 {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public string recordtypetext {get;set;}
    public Satisfaction_Surveys__c survey {get;set;}
    

  public CreateSatisfactionSurvey2 (ApexPages.StandardController controller) {
        stdCntrlr = controller; 
     if (survey == null)
        survey = new Satisfaction_Surveys__c ();
  }

  // save button is clicked
  public PageReference save() {
		
    try {
		recordtypetext = ApexPages.CurrentPage().getParameters().get('recordtypetext');
        survey.RecordTypeId = recordtypetext;
        system.debug(recordtypetext);
        insert survey; // inserts the new record into the database
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new survey.'));
      return null;
    }

    // if successfully inserted new survey, then displays the thank you page.
    return Page.Survey_Create_Thankyou;
  }

}

 
Greetings all,
I have a visualforce page with an apex:inputfield for ownerid for the record to create a timesheet.  I am currently defaulting the field to the current user (the current user will usually be creating a timesheet for themselves), but would like the ability to change the value in the owner field if they choose.  Currently the field is defaulting correctly, but if the user changes from the default user to another user, the value doesn't save (it goes back to the default value/current user).  I assume some problem with my controller.  Please advise. 

Thanks,
Collen

My code is below.
 
<apex:page standardController="Timesheet__c" extensions="PayPeriodExtension">
   
    <apex:form >
            
    <apex:pageBlock title="Select Pay Period">
      <apex:pageMessages /> <!-- this is where the error messages will appear -->

        <apex:pageBlockSection >
                
       	<apex:selectList size="1" required="true" value="{!PayPeriodID}">
          <apex:selectOptions value="{!ActivePayperiods}"></apex:selectOptions>
      	</apex:selectList>
        <apex:inputfield value="{!OwnerID}"/>	<br/>

        </apex:pageBlockSection>
            <apex:pageBlockButtons >
            <apex:commandButton action="{! save }" value="Save" />        
        	<apex:commandButton action="{! cancel }" value="Cancel" />        
        </apex:pageBlockButtons>      
    </apex:pageBlock>
 </apex:form>
           
</apex:page>

Extension:
 
public class PayPeriodExtension {
    public ApexPages.StandardController stdCntrlr {get; set;}
    Public List  <Pay_Period__c> PPTemp = new List <Pay_Period__c>(); 
    Public String PayPeriodID {get; set;}
   
    // the contact record you are adding values to
  public Timesheet__c timesheet {
    get {
      if (timesheet == null)
        timesheet = new Timesheet__c ();
        timesheet.OwnerId = UserInfo.getUserId();
        return timesheet;
    }
    set;
  }
	public  PayPeriodExtension(ApexPages.StandardController controller) {
        stdCntrlr = controller;    
  }

   
    public List<SelectOption> ActivePayperiods
    {
        get
        {
            PPTemp = [Select Id, Name, Days_Since_Start_Date__c From Pay_Period__c 
                      Where (Days_Since_Start_Date__c <14 AND days_Since_Start_Date__c >-21) 
                      Order BY Days_Since_Start_Date__c desc ];
            ActivePayPeriods = new List<SelectOption>();
            
            for(Pay_Period__c temp : PPTemp)
            {
                ActivePayPeriods.add(new SelectOption(temp.id, temp.Name));
            }
            return ActivePayPeriods;
        }
        set;
    }
    
    public PageReference save() {
		
    try {
        timesheet.Pay_Period__c = PayPeriodID;
        upsert timesheet; // inserts the new record into the database
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new timesheet.'));
      return null;
    }

    // if successfully inserted new survey, then displays the thank you page.
    return (new ApexPages.StandardController(timesheet)).view();
  }

}


 
Greetings all,
I have a visualforce page with an apex:inputfield for ownerid for the record to create a timesheet.  I would like to default the record owner name on the page to the current user (the current user will usually be creating a timesheet for themselves), but give them the ability to change the value in the owner field if they choose.  Currently the field is coming up blank, rather than with the current user.  Please advise.  My code is below.

I'm still pretty new to apex so any help is greatly appreciated. 

My VF page:
<apex:page standardController="Timesheet__c" extensions="PayPeriodExtension">
   
    <apex:form >
            
    <apex:pageBlock title="Select Pay Period">
      <apex:pageMessages /> <!-- this is where the error messages will appear -->

        <apex:pageBlockSection >
                
       	<apex:selectList size="1" required="true" value="{!PayPeriodID}">
          <apex:selectOptions value="{!ActivePayperiods}"></apex:selectOptions>
      	</apex:selectList>
        <apex:inputfield value="{!Timesheet__c.ownerid}"/>	<br/>

        </apex:pageBlockSection>
            <apex:pageBlockButtons >
            <apex:commandButton action="{! save }" value="Save" />        
        	<apex:commandButton action="{! cancel }" value="Cancel" />        
        </apex:pageBlockButtons>      
    </apex:pageBlock>
 </apex:form>
           
</apex:page>
My Controller Extension:
 
public class PayPeriodExtension {
    public ApexPages.StandardController stdCntrlr {get; set;}
    Public List  <Pay_Period__c> PPTemp = new List <Pay_Period__c>(); 
    Public String PayPeriodID {get; set;}
   
    // the contact record you are adding values to
  public Timesheet__c timesheet {
    get {
      if (timesheet == null)
        timesheet = new Timesheet__c ();
        timesheet.OwnerId = UserInfo.getUserId();
        return timesheet;
    }
    set;
  }
	public  PayPeriodExtension(ApexPages.StandardController controller) {
        stdCntrlr = controller;    
  }

   
    public List<SelectOption> ActivePayperiods
    {
        get
        {
            PPTemp = [Select Id, Name, Days_Since_Start_Date__c From Pay_Period__c 
                      Where (Days_Since_Start_Date__c <14 AND days_Since_Start_Date__c >-21) 
                      Order BY Days_Since_Start_Date__c desc ];
            ActivePayPeriods = new List<SelectOption>();
            
            for(Pay_Period__c temp : PPTemp)
            {
                ActivePayPeriods.add(new SelectOption(temp.id, temp.Name));
            }
            return ActivePayPeriods;
        }
        set;
    }
    
    public PageReference save() {
		
    try {
        timesheet.Pay_Period__c = PayPeriodID;
        upsert timesheet; // inserts the new record into the database
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new timesheet.'));
      return null;
    }

    // if successfully inserted new survey, then displays the thank you page.
    return (new ApexPages.StandardController(timesheet)).view();
  }

}



 
Hi All,
I have a custom object called Satisfaction Surveys.  I will have multiple visualforce pages that allow the user to fill out a satisfaction survey of a given record type depending on the service they receieved.  I have the following controller that works well, but I would like to pass it a recordtype id from the visualforce page.  How would i do that?  Record type 1 would be survey for service 1 and Record type 2 would be a different survey for service 2. Visualforce page 1 would create a survey of record type 1 and visual force page 2 would create a survey of record type 2.  I assume I could do this all with the single controller:
 
public with sharing class CreateSatisfactionSurvey {

  // the contact record you are adding values to
  public 	Satisfaction_Surveys__c survey {
    get {
      if (survey == null)
        survey = new Satisfaction_Surveys__c ();
      return survey;
    }
    set;
  }

  public CreateSatisfactionSurvey() {
    // blank constructor
  }

  // save button is clicked
  public PageReference save() {

    try {
      insert survey; // inserts the new record into the database
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new survey.'));
      return null;
    }

    // if successfully inserted new survey, then displays the thank you page.
    return Page.Survey_Create_Thankyou;
  }

}

A sample visualforce page (which I would like to modify based on survey type/record type) is:
 
<apex:page Controller="CreateSatisfactionSurvey">  
  <apex:sectionHeader title="Satisfaction Survey" subtitle="Please rate the service you receieved."/>

  <apex:form >
    <apex:pageMessages /> <!-- this is where the error messages will appear -->
    <apex:pageBlock title="Survey Response">

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

      <apex:pageBlockSection showHeader="false" columns="2">
      	<apex:inputField value="{!survey.Program__c}" />  
          <apex:inputField value="{!survey.Access_Comm_Resources__c}" />
      </apex:pageBlockSection>

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

Thanks,
Collen
 
Hello all,
I"m trying to use an apex variable in my visualforce page to keep a running total of a client's balance on a custom object.  I'm getting a strange error "the value 'core.apexpages.el.adapters.RuntimeTypeMetadataElAdapter@75251df1' is not a valid number."  I think it may have something to do with how I'm referring to the map field but can't figure out how to do it differently.  I have verified that my controller is functioning properly, that records are populating, etc.  I only get the error when trying to display the variable; if I delete the "OutputText" tag, the error goes away which seems strange to me. 

Here's a trimmed down version of my Visualforce code that reproduces the error:
 
<apex:page standardController="AECaseMgmt__Program_Case__c" extensions="Invoice"   sidebar="false" showHeader="false" >
   
   <apex:repeat value="{!MapCasetoBilling}" var="Key">

        	<apex:variable value="{!0}" var="RunningBalance"/>
       			<table>   
                   <apex:repeat value="{!MapCasetoBilling[Key]}" var="BillingItem">
                        <apex:variable value="{!0}" var="RunningBalance"/>

                	<apex:variable var="RunningBalance" value="{!BillingItem['Amount_Credit_Debit__c']+RunningBalance}"/>
                       <apex:outputText value="{!RunningBalance}"/><br/>

            	</apex:repeat>
       		</table>
             </apex:repeat>
</apex:page>
Thanks,
Collen
 
Hello All,
Is there anyway to update a totals field at the bottom of a visualforce page as the user updates a numeric field on multiple related records on a visualforce page (without saving/refreshing the page)? 

Suppose the data looks like this:

        Hours
6/1     7
6/2     3
6/3     3
Total 13

"Hours" in an input field for the time entry record and the total could either be a visualforce component or a roll-up field on the parent record (summing the time entries).  As the user changes hours on various days, I'd like for the total to automatically update. 

Any help is appreciated.  Thanks!

Collen
Hi All,
I've got a map in my controller that is populating fine:
 
public Map <id,List<Client_Billing__c>> mapCaseToBilling {get;set;}
However, I'm having trouble with my visualforce page nested repeat loops.  I'm getting inside the first one but not the second.  I'm sure I'm using the wrong syntax somehow.  Any help is appreciated:
<apex:page StandardController="AECaseMgmt__Program_Case__c" extensions="Invoice" >
    <apex:repeat value="{!MapCasetoBilling}" var="Key">
        This will print:{!Key}
        <apex:repeat value="{!MapCasetoBilling[Key]}" var="BillingItem">
            This line will not print.
            <apex:outputField value="BillingItem.Name"/>
        </apex:repeat>
    </apex:repeat>

</apex:page>


 
Hi All,
I'm working on a visualforce controller to produce multiple invoices, for any client case that has billing items.   Each billing item has exactly one client case (each client case may have one or more billing items).  I'm getting stuck on the map line below.  Currently I am getting the error, "Incompatible list type List for putAll on Map>".  I'm assuming I can't use putAll in this case?  Can someone suggest an alternative of how this might be done?  Any help, suggestions, improvements are appreciated.  

Thanks,
Collen
 
public class Invoice {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public List<Client_Billing__c> billingList {get;set;}
    public List<AECaseMgmt__Program_Case__c> CaseQueryResults {get;set;}
    public AECaseMgmt__Program_Case__c Clientcase {get;set;}
	public Map <id,List<Client_Billing__c>> mapCaseToBilling;       
    
    public list <BillingEntry> caseList {get; set;}
    public Invoice(ApexPages.StandardController controller) {
        stdCntrlr = controller;
      	mapCaseToBilling = new map <id, List<Client_Billing__c>>();
        mapCaseToBilling.putAll([Select id, (Select id, Client_Case__c from Billing_Items__r) 
                            from AECaseMgmt__Program_Case__c WHERE Id IN :mapCaseToBilling.keySet()]);
        
   for(AECaseMgmt__Program_Case__c cc : CaseQueryResults)
    {
        BillingEntry be = new BillingEntry (cc);
           
        for (Client_Billing__c cb: mapCaseToBilling.get(cc.Id))    
        {
            be.billingList.add(cb);
        }
    }
   
   }


	Public class BillingEntry
    {
        public List<Client_Billing__c> billingList {get;set;}
        Public AECaseMgmt__Program_Case__c Clientcase {get;set;}
        
        public BillingEntry (AECaseMgmt__Program_Case__c cc)
        {
            Clientcase = cc;
            billingList = new list<Client_Billing__c>();
        }
    }
}

 
All,
I'm working on a visualforce controller to generate multiple invoices with multiple billing items (Client_Billing__c) per invoice.  Each invoice is tied to one and only one client case (AECaseMgmt__Program_Case__c).  I found some very helpful code that I'm modifying for my needs (I'm still an Apex novice) but need a little help with one line of the code:
 
for (Client_Billing__c cb: mapCaseToResults.get(cc.Id))
The sample code I'm modifying did not have a delcaration for "MapCaseToResults" and I'm having trouble understanding the complex syntax.  Could someone help me with the declaration and perhaps an explanation of the syntax?  Currently my code is getting the error: "Method does not exist or incorrect signature: [List].get(Id)." 

Here is my complete controller code:
public class Invoice {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public List<Client_Billing__c> billingList {get;set;}
    public List<AECaseMgmt__Program_Case__c> CaseQueryResults {get;set;}
    public AECaseMgmt__Program_Case__c Clientcase {get;set;}
    public List<Client_Billing__c> mapCaseToResults {get; set;}
    public list <BillingEntry> caseList {get; set;}
    public Invoice(ApexPages.StandardController controller) {
        stdCntrlr = controller;
     	billingList = [Select id, Date__c, Client_Case__c, Amount__c, Amount_Credit_Debit__c,
                       Transaction_Description__c
                       from Client_Billing__c];
      caseQueryResults = [Select id from AECaseMgmt__Program_Case__c];
      
   for(AECaseMgmt__Program_Case__c cc : CaseQueryResults)
    {
        BillingEntry be = new BillingEntry (cc);
        for (Client_Billing__c cb: mapCaseToResults.get(cc.Id))    
        {
            be.billingList.add(cb);
        }
    }
   
   }


	Public class BillingEntry
    {
        public List<Client_Billing__c> billingList {get;set;}
        Public AECaseMgmt__Program_Case__c Clientcase {get;set;}
        
        public BillingEntry (AECaseMgmt__Program_Case__c cc)
        {
            Clientcase = cc;
            billingList = new list<Client_Billing__c>();
        }
	}
}
I'm very open to learning so any help is much appreciated!

Best,
Collen


 
All,
I currently have a ClientBilling object that is the child of the parent ClientCase (MasterDetail).  I have a visualforce page that creates an invoice from a Detail Page Button for the clientcase, pulling all clientbilling entries for a given clientcase. 

I'm wondering how I might go about creating multiple clientcase invoices from a button or tab.  For example, in visual force create invoices for ALL clientcases with status field marked "active."  What would the SOQL look like in this case (pulling all billing items for clientcases with active status)?  Also can someone given an example of how I might do the nested loop in my visual force (looping through clientcases and then looping through billing item of each clientcase)?

If anyone can get me started I woudl be most grateful!

Best,
Collen
Hi All,
I've written this simple controller extension for a VF page and am having trouble with the Save method; the changes I make to a record from the page are not saving after I click "save".  Do you see problems with my code?
 
public class Timesheet {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public List<Timesheet_Entry__c> timeentryList {get;set;}
    public TimeSheet__c timesheet;
    public Timesheet(ApexPages.StandardController controller) {
        stdCntrlr = controller;
    
    
    timesheet = (TimeSheet__c)controller.getRecord();
     
    timeentryList = [Select id, Date__c, Time_in_1__c, Time_in_2__c, Time_Out_1__c, Time_Out_2__c, Work_Hours__c, Holiday_Hours__c, Vacation_Hours__c, Personal_Hours__c, Other_Hours__c, Total_Hours__c from Timesheet_Entry__c where TimeSheet__c =: timesheet.ID];
    }
        

 public PageReference SaveTS(){
	upsert timesheet; 
 	upsert timeentryList;
    return (new ApexPages.StandardController(timesheet)).view();
 } 
}
Here is a snippet of the Visualforce page:
 
<apex:page standardController="Timesheet__c" extensions="Timesheet" sidebar="false" showHeader="true" docType="html-5.0">
 <apex:form >		
 		<apex:pageBlock title="Hours Worked" >
    <table>
<apex:repeat var="TSE" value="{!Timesheet__c.Timesheet_Entries__r}">
      <tr>
          <td >
              <apex:outputField value="{!TSE.Date__c}"/>             
     	  </td>
          <td >
              <apex:inputField value="{!TSE.Time_Out_1__c}"/>             
           </td>
     </tr>
-
-
- (other code)
-
               <apex:commandButton value="Save" action="{!saveTS}" />
        	</apex:pageBlockButtons>
       			</table>
     		</apex:pageBlock>
        </apex:form>
</apex:page>
Any help would be appreciated. 

Thanks,
Collen
 
Hi All,
I have a object called "time_entry__c" that includes the following fields: date__c, time_in__c, time_out__c.  The date field is date format, and the time in/out fields are date/time format (though if there was a better format option for these fields, they wouldn't have to be date/time).  For a timesheet visual force page I'm creating, for the time_in and time_out I'd like to have the user input the time (in time format, 12:00) and use the date from the date field in what is saved in the date/time format.  Can anyone point me in the right direction, or suggest an easier way that the user can enter time in a visual force page? 

Thanks,
Collen
 Hi,
I have an invoice visual force page that generates from a detail page button as a PDF. It works fine.  I would like to have functionality where I can generate multiple pages for multiple records on the same mulipage Pdf based on criteria. For example, generate the invoice for any account with a balance. Can someone point me to a post or reference to get me started?

best,
collen
Hi All,
I have a visual force page that allows a user to enter/edit their mileage expenses.  All is working fine, but I'm needing to have a column heading rerender when a user hits a "refresh programs" button, but I'm not having any luck.  Here is a simplified version of the page:
 
<apex:page standardController="Expense_Report__c" extensions="addMileageExpense" sidebar="false" showHeader="true">
 <apex:form >		
 		<apex:pageBlock title="Mileage Report" id="er" >
    <table>     
      <tr>
          <td style="width:85px">
          		<h2>Program 1:</h2>
          </td>
          <td style="width:175px">
          		<apex:inputField value="{!Expense_Report__c.Program_1_Mileage_log__c}">          
           		</apex:inputField>
     	  </td>
        <td><apex:commandButton value="Refresh programs" action="{!refreshProgram}" reRender="program_num"></apex:commandButton></td>
        </tr>
    </table>
            <apex:pageMessages />
 		<apex:variable var="rowNumber" value="{!0}"/>
               <apex:pageblockSection columns="1" > 
 					
                   <apex:pageBlockTable title="Mileage Expenses" var="me" value="{!expenseList}" > 
  
 					<apex:column headerValue="Entry" style="width:20px; text-align:center;" headerClass="centertext">
 						<apex:outputText value="{0}" style="text-align:center;"> 
 							<apex:param value="{!rowNumber+1}" /> 
 						</apex:outputText>
					</apex:column> 
 					
                    <apex:column headerValue="Date of trip" >
                       <apex:inputField value="{!me.Date__c}"  required="true"/>
 					                    </apex:column>
                    
                    <apex:column headerValue="Purpose and Description" >
                       <apex:inputField value="{!me.Name}" required="true"/>
 					</apex:column> 
                    <apex:column headerValue="{! Expense_Report__c.Program_1_Number__c}" 
                                 style="width:50px" id="program_num">
                        <apex:inputField value="{!me.Prgm_1_Miles__c}" style="width:50px">
                        </apex:inputField>
                    </apex:column>
                 </apex:pageBlockTable>
             </apex:pageblockSection>                            
 		</apex:pageBlock> 		
 	</apex:form> 
 </apex:page>

The refresh program button simply upserts the existing expense report record after the "program 1" field is changed (and this is working ).  What I'm having problems with is getting the last column heading to rerender after the user changes program and hits the refresh program button.  The last column heading, Expense_Report__c.Program_1_Number__c, is a formula field based on program 1.  On a side note, if I refresh my browser after hitting refresh programs button, it does update the column heading, but  I'm trying to do this without refreshing the whole page. 

I'm new to visualforce so any help/advice is appreciated.

Best,
Collen
I'm very, very new to working with visual force and need to write a testclass for my controller below.  Could someone help get me started?  Many thanks in advance.

Best,
Collen
 
public class addMileageExpense {
public Expense_Report__c reports;
 public Mileage_expense__c del;
 public List<Mileage_expense__c> addexpenseList {get;set;}
 public List<Mileage_expense__c> delexpenseList {get;set;}
 public List<Mileage_expense__c> expenseList {get;set;}
 public Integer totalCount {get;set;}
 public Integer rowIndex {get;set;}
 public List<Mileage_expense__c> delexpense {get; set;} 
 public addMileageExpense(ApexPages.StandardController controller) {
 
 reports = (Expense_Report__c)controller.getRecord();
 expenseList = [Select id, Name, Expense_Report__c, Miles__c, Total_Miles__c,   
                Date__c, Prgm_1_Miles__c, Prgm_2_Miles__c, Prgm_3_Miles__c, Prgm_4_Miles__c, 
                Prgm_5_Miles__c, Prgm_6_Miles__c from Mileage_expense__c where Expense_Report__c =: reports.ID];
 totalCount = expenseList.size();
 
 delexpenseList = new List<Mileage_expense__c>();
 delexpense = new List<Mileage_expense__c>();
 }
 
 public void addRow(){
 addexpenseList = new List<Mileage_expense__c>();
 expenseList.add(new Mileage_expense__c(Expense_Report__c = reports.Id));
 }
 
 public PageReference ave(){
 
 upsert expenseList;
 delete delexpenseList;
 return (new ApexPages.StandardController(reports)).view();
 } 
 
 public void deleteRow(){
 
 rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
 System.debug('row to be deleted ' + rowIndex );
 System.debug('row to be deleted '+ expenseList[rowIndex]);

     del = expenseList.remove(rowIndex);
     If(del.Id <> null) {delexpenseList.add(del);}
         
 
     }
 }
 
 
I've got a visualforce page with javascript formulas totaling records at the bottom.  I've recently added the ability to add a row to the page by clicking a button.  However the size of my list (!PayrollDistributionList.size) is not increasing when I do that (unless I "save" and refresh the page), so my column total ends up incorrect, and it doesn't iterate over all the rows.   Can someone provide some guidance?

My page:
<apex:page standardController="Payroll_Authorization__c" sidebar="false" doctype="html-5.0" standardStylesheets="false" extensions="PayrollAuthorization_extn" applyBodyTag="true" lightningStylesheets="true">
<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
      .form-control {
          padding: 6px !important;
      }
      .btn-info {
        color: #fff!important;
        background-color: #5bc0de !important;
        border-color: #46b8da !important;
        background-image: none !important;
        padding: 8px 20px !important;
    }
     .table>thead>tr>th{
            vertical-align: top !important;
            text-align: left !important;
      }
      .table>tbody>tr>td{
            vertical-align: top !important;
            text-align: left !important;
      }
      .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
            padding: 4px !important;
        }
        .list-group-item {
            padding: 6px 15px !important;
        }
  </style>
	<script>
	      
    function calctotal(){
          alert ("caltotal" + {!PayrollDistributionList.size}); 
          var tempRowTotal=0;
          var percenttotal= 0;
        for(var i=1; i<={!PayrollDistributionList.size};i++ ){
              
              tempRowTotal = ($('.wh'+i).val()!= null && $('.wh'+i).val() != '')?parseFloat($('.wh'+i).val()):0.0;
              percenttotal  += tempRowTotal;
              
          	}
        return percenttotal;   
    }
      
    function calcRow(){
          alert ("calrow"); 
          
        var tempRowTotal=0;
         var percenttotal= 0;
           percenttotal= calctotal(); 
 		for(var i=1; i<={!PayrollDistributionList.size};i++ ){	
          tempRowTotal = ($('.wh'+i).val()!= null && $('.wh'+i).val() != '')?parseFloat($('.wh'+i).val()):0.0;
          $('.wp' + i).text(((tempRowTotal * 100)/percenttotal).toFixed(2)+'%');
          $('.percenttotal').text(percenttotal.toFixed(2)+'%');		
          }
      }
    
    $(document).ready(function(){
              {
                  calcRow();
         	  }

      });
    </script>
    </head>
<body>
	<apex:form >
        <apex:pageBlock title="Payroll Distribution" id="er" >
		<div align="center" draggable="false" style="font-size:13px; margin-bottom:4px"  >
    		<apex:commandButton value="Save" action="{!SavePA}" styleclass="btn btn-info" style="" />&nbsp;&nbsp;
    		<apex:commandButton value="Cancel" action="{!Cancel}" styleclass="btn btn-info" immediate="true"/>
		</div>
		<div class="container-flud" style="font-size: 11.5px;">
    		<apex:pageMessages ></apex:pageMessages>
    		<div class="col-md-12" style="margin-bottom: -15px;">
        		<ul class="list-group">      
            		<li class="list-group-item row" style="background-color: #702342;color: #fff;padding: 6px 10px;">
                		<h4 style="margin: 2px 0px;font-size: 12px;font-weight: bolder;">Payroll Authorization</h4>
            		</li>
        		</ul>

      <div class="col-md-12" style="margin-bottom: 15px;">
        <ul class="list-group">      
            <li class="list-group-item row" style="background-color: #702342;color: #fff;padding: 6px 10px;">
                <h4 style="margin: 2px 0px;font-size: 12px;font-weight: bolder;">Payroll Distributions</h4>
            </li>
        </ul>
    	</div>
	<table class="table table-bordered" >
                   
                <thead>
                <tr>
                <th>
                    Program
                </th>
                <th>
                    Percentage worked
                </th>
                <th>
                	Percentage total
                </th>
              </tr>
                </thead>
                <tbody>
                    <apex:variable value="{!1}" var="index"/>  
                <apex:repeat value="{!PayrollDistributionList}" var="pd">
                    <tr>
                        <td><apex:inputfield value="{!pd.Program__c}"   style="Width: 50%"/></td>
                        <td ><apex:inputfield value="{!pd.Program_Percent__c}" styleClass="wh{!index}" onkeyup="calcRow()"/> </td>
                    	<td Class="wp{!index}">
                    		0%
                		</td>
                    </tr>
                    <apex:variable value="{!index+1}" var="index"/>
                   
                </apex:repeat>
    		</tbody>
        <tfoot> <tr>
                <th>
                </th>
                <th class="percenttotal">
                    0.0%
                </th>
                <th>
                	100.00%
                </th>
              </tr></tfoot>
          </table>
          </div>
   		</div>
    <apex:commandButton action="{!addRow}" value="Add Program" immediate="true" reRender="er"/>
        </apex:pageBlock>
        </apex:form>
    
    </body>
</apex:page>
My extension: 
 
public with sharing class PayrollAuthorization_extn {
   
    public list <PA_Distribution__c> PayrollDistributionList {get; set;}
    public Payroll_Authorization__c PA;
    
    
    public PayrollAuthorization_extn(ApexPages.StandardController controller) {
        
  	PA = (Payroll_Authorization__c)controller.getRecord();
  	PayrollDistributionList = [Select Id, Name, Program__r.Name, Program_Percent__c
 			From PA_Distribution__c
      		Where Payroll_Authorization__r.id =: controller.getId()];  
                
    }
    
    public void addRow(){
 		PayrollDistributionList.add(new PA_Distribution__c(	Payroll_Authorization__c = PA.id));
	}
    
    public void SavePA (){
        upsert PA; 
        upsert PayrollDistributionList;
    }
    
    
}


 
Hi All,
I'm need to pass a recordtype id from a visualforce page to my controller extension.  However debug log is showing the variable in the controller I'm trying to set is NULL (not getting the value from the visualforce page).  Here's what I've tried.  Any help/feedback would be greatly appreciated.  
Best,
Collen 

My test page: 
 
<apex:page standardController="Satisfaction_Surveys__c" extensions="CreateSatisfactionSurvey2">  
  <apex:sectionHeader title="Satisfaction Survey" subtitle="Please rate the service you receieved."/>

  <apex:form >
     
    <apex:pageMessages /> 
    <apex:pageBlock title="Survey Response">
        

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

      <apex:pageBlockSection showHeader="false" columns="2">
          <apex:inputField value="{!survey.Access_Comm_Resources__c}" />
      <apex:param assignTo="{!recordtypetext}" value="01236000000xk08" name="recordtypetext"/> 

        </apex:pageBlockSection>

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

My controller:
 
public  class CreateSatisfactionSurvey2 {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public string recordtypetext {get;set;}
    public Satisfaction_Surveys__c survey {get;set;}
    

  public CreateSatisfactionSurvey2 (ApexPages.StandardController controller) {
        stdCntrlr = controller; 
     if (survey == null)
        survey = new Satisfaction_Surveys__c ();
  }

  // save button is clicked
  public PageReference save() {
		
    try {
		recordtypetext = ApexPages.CurrentPage().getParameters().get('recordtypetext');
        survey.RecordTypeId = recordtypetext;
        system.debug(recordtypetext);
        insert survey; // inserts the new record into the database
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new survey.'));
      return null;
    }

    // if successfully inserted new survey, then displays the thank you page.
    return Page.Survey_Create_Thankyou;
  }

}

 
Greetings all,
I have a visualforce page with an apex:inputfield for ownerid for the record to create a timesheet.  I would like to default the record owner name on the page to the current user (the current user will usually be creating a timesheet for themselves), but give them the ability to change the value in the owner field if they choose.  Currently the field is coming up blank, rather than with the current user.  Please advise.  My code is below.

I'm still pretty new to apex so any help is greatly appreciated. 

My VF page:
<apex:page standardController="Timesheet__c" extensions="PayPeriodExtension">
   
    <apex:form >
            
    <apex:pageBlock title="Select Pay Period">
      <apex:pageMessages /> <!-- this is where the error messages will appear -->

        <apex:pageBlockSection >
                
       	<apex:selectList size="1" required="true" value="{!PayPeriodID}">
          <apex:selectOptions value="{!ActivePayperiods}"></apex:selectOptions>
      	</apex:selectList>
        <apex:inputfield value="{!Timesheet__c.ownerid}"/>	<br/>

        </apex:pageBlockSection>
            <apex:pageBlockButtons >
            <apex:commandButton action="{! save }" value="Save" />        
        	<apex:commandButton action="{! cancel }" value="Cancel" />        
        </apex:pageBlockButtons>      
    </apex:pageBlock>
 </apex:form>
           
</apex:page>
My Controller Extension:
 
public class PayPeriodExtension {
    public ApexPages.StandardController stdCntrlr {get; set;}
    Public List  <Pay_Period__c> PPTemp = new List <Pay_Period__c>(); 
    Public String PayPeriodID {get; set;}
   
    // the contact record you are adding values to
  public Timesheet__c timesheet {
    get {
      if (timesheet == null)
        timesheet = new Timesheet__c ();
        timesheet.OwnerId = UserInfo.getUserId();
        return timesheet;
    }
    set;
  }
	public  PayPeriodExtension(ApexPages.StandardController controller) {
        stdCntrlr = controller;    
  }

   
    public List<SelectOption> ActivePayperiods
    {
        get
        {
            PPTemp = [Select Id, Name, Days_Since_Start_Date__c From Pay_Period__c 
                      Where (Days_Since_Start_Date__c <14 AND days_Since_Start_Date__c >-21) 
                      Order BY Days_Since_Start_Date__c desc ];
            ActivePayPeriods = new List<SelectOption>();
            
            for(Pay_Period__c temp : PPTemp)
            {
                ActivePayPeriods.add(new SelectOption(temp.id, temp.Name));
            }
            return ActivePayPeriods;
        }
        set;
    }
    
    public PageReference save() {
		
    try {
        timesheet.Pay_Period__c = PayPeriodID;
        upsert timesheet; // inserts the new record into the database
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new timesheet.'));
      return null;
    }

    // if successfully inserted new survey, then displays the thank you page.
    return (new ApexPages.StandardController(timesheet)).view();
  }

}



 
Hello all,
I"m trying to use an apex variable in my visualforce page to keep a running total of a client's balance on a custom object.  I'm getting a strange error "the value 'core.apexpages.el.adapters.RuntimeTypeMetadataElAdapter@75251df1' is not a valid number."  I think it may have something to do with how I'm referring to the map field but can't figure out how to do it differently.  I have verified that my controller is functioning properly, that records are populating, etc.  I only get the error when trying to display the variable; if I delete the "OutputText" tag, the error goes away which seems strange to me. 

Here's a trimmed down version of my Visualforce code that reproduces the error:
 
<apex:page standardController="AECaseMgmt__Program_Case__c" extensions="Invoice"   sidebar="false" showHeader="false" >
   
   <apex:repeat value="{!MapCasetoBilling}" var="Key">

        	<apex:variable value="{!0}" var="RunningBalance"/>
       			<table>   
                   <apex:repeat value="{!MapCasetoBilling[Key]}" var="BillingItem">
                        <apex:variable value="{!0}" var="RunningBalance"/>

                	<apex:variable var="RunningBalance" value="{!BillingItem['Amount_Credit_Debit__c']+RunningBalance}"/>
                       <apex:outputText value="{!RunningBalance}"/><br/>

            	</apex:repeat>
       		</table>
             </apex:repeat>
</apex:page>
Thanks,
Collen
 
Hello All,
Is there anyway to update a totals field at the bottom of a visualforce page as the user updates a numeric field on multiple related records on a visualforce page (without saving/refreshing the page)? 

Suppose the data looks like this:

        Hours
6/1     7
6/2     3
6/3     3
Total 13

"Hours" in an input field for the time entry record and the total could either be a visualforce component or a roll-up field on the parent record (summing the time entries).  As the user changes hours on various days, I'd like for the total to automatically update. 

Any help is appreciated.  Thanks!

Collen
Hi All,
I'm working on a visualforce controller to produce multiple invoices, for any client case that has billing items.   Each billing item has exactly one client case (each client case may have one or more billing items).  I'm getting stuck on the map line below.  Currently I am getting the error, "Incompatible list type List for putAll on Map>".  I'm assuming I can't use putAll in this case?  Can someone suggest an alternative of how this might be done?  Any help, suggestions, improvements are appreciated.  

Thanks,
Collen
 
public class Invoice {
    public ApexPages.StandardController stdCntrlr {get; set;}
    public List<Client_Billing__c> billingList {get;set;}
    public List<AECaseMgmt__Program_Case__c> CaseQueryResults {get;set;}
    public AECaseMgmt__Program_Case__c Clientcase {get;set;}
	public Map <id,List<Client_Billing__c>> mapCaseToBilling;       
    
    public list <BillingEntry> caseList {get; set;}
    public Invoice(ApexPages.StandardController controller) {
        stdCntrlr = controller;
      	mapCaseToBilling = new map <id, List<Client_Billing__c>>();
        mapCaseToBilling.putAll([Select id, (Select id, Client_Case__c from Billing_Items__r) 
                            from AECaseMgmt__Program_Case__c WHERE Id IN :mapCaseToBilling.keySet()]);
        
   for(AECaseMgmt__Program_Case__c cc : CaseQueryResults)
    {
        BillingEntry be = new BillingEntry (cc);
           
        for (Client_Billing__c cb: mapCaseToBilling.get(cc.Id))    
        {
            be.billingList.add(cb);
        }
    }
   
   }


	Public class BillingEntry
    {
        public List<Client_Billing__c> billingList {get;set;}
        Public AECaseMgmt__Program_Case__c Clientcase {get;set;}
        
        public BillingEntry (AECaseMgmt__Program_Case__c cc)
        {
            Clientcase = cc;
            billingList = new list<Client_Billing__c>();
        }
    }
}

 
All,
I currently have a ClientBilling object that is the child of the parent ClientCase (MasterDetail).  I have a visualforce page that creates an invoice from a Detail Page Button for the clientcase, pulling all clientbilling entries for a given clientcase. 

I'm wondering how I might go about creating multiple clientcase invoices from a button or tab.  For example, in visual force create invoices for ALL clientcases with status field marked "active."  What would the SOQL look like in this case (pulling all billing items for clientcases with active status)?  Also can someone given an example of how I might do the nested loop in my visual force (looping through clientcases and then looping through billing item of each clientcase)?

If anyone can get me started I woudl be most grateful!

Best,
Collen
Hi All,
I have a object called "time_entry__c" that includes the following fields: date__c, time_in__c, time_out__c.  The date field is date format, and the time in/out fields are date/time format (though if there was a better format option for these fields, they wouldn't have to be date/time).  For a timesheet visual force page I'm creating, for the time_in and time_out I'd like to have the user input the time (in time format, 12:00) and use the date from the date field in what is saved in the date/time format.  Can anyone point me in the right direction, or suggest an easier way that the user can enter time in a visual force page? 

Thanks,
Collen
Hi All,
I have a visual force page that allows a user to enter/edit their mileage expenses.  All is working fine, but I'm needing to have a column heading rerender when a user hits a "refresh programs" button, but I'm not having any luck.  Here is a simplified version of the page:
 
<apex:page standardController="Expense_Report__c" extensions="addMileageExpense" sidebar="false" showHeader="true">
 <apex:form >		
 		<apex:pageBlock title="Mileage Report" id="er" >
    <table>     
      <tr>
          <td style="width:85px">
          		<h2>Program 1:</h2>
          </td>
          <td style="width:175px">
          		<apex:inputField value="{!Expense_Report__c.Program_1_Mileage_log__c}">          
           		</apex:inputField>
     	  </td>
        <td><apex:commandButton value="Refresh programs" action="{!refreshProgram}" reRender="program_num"></apex:commandButton></td>
        </tr>
    </table>
            <apex:pageMessages />
 		<apex:variable var="rowNumber" value="{!0}"/>
               <apex:pageblockSection columns="1" > 
 					
                   <apex:pageBlockTable title="Mileage Expenses" var="me" value="{!expenseList}" > 
  
 					<apex:column headerValue="Entry" style="width:20px; text-align:center;" headerClass="centertext">
 						<apex:outputText value="{0}" style="text-align:center;"> 
 							<apex:param value="{!rowNumber+1}" /> 
 						</apex:outputText>
					</apex:column> 
 					
                    <apex:column headerValue="Date of trip" >
                       <apex:inputField value="{!me.Date__c}"  required="true"/>
 					                    </apex:column>
                    
                    <apex:column headerValue="Purpose and Description" >
                       <apex:inputField value="{!me.Name}" required="true"/>
 					</apex:column> 
                    <apex:column headerValue="{! Expense_Report__c.Program_1_Number__c}" 
                                 style="width:50px" id="program_num">
                        <apex:inputField value="{!me.Prgm_1_Miles__c}" style="width:50px">
                        </apex:inputField>
                    </apex:column>
                 </apex:pageBlockTable>
             </apex:pageblockSection>                            
 		</apex:pageBlock> 		
 	</apex:form> 
 </apex:page>

The refresh program button simply upserts the existing expense report record after the "program 1" field is changed (and this is working ).  What I'm having problems with is getting the last column heading to rerender after the user changes program and hits the refresh program button.  The last column heading, Expense_Report__c.Program_1_Number__c, is a formula field based on program 1.  On a side note, if I refresh my browser after hitting refresh programs button, it does update the column heading, but  I'm trying to do this without refreshing the whole page. 

I'm new to visualforce so any help/advice is appreciated.

Best,
Collen
I'm very, very new to working with visual force and need to write a testclass for my controller below.  Could someone help get me started?  Many thanks in advance.

Best,
Collen
 
public class addMileageExpense {
public Expense_Report__c reports;
 public Mileage_expense__c del;
 public List<Mileage_expense__c> addexpenseList {get;set;}
 public List<Mileage_expense__c> delexpenseList {get;set;}
 public List<Mileage_expense__c> expenseList {get;set;}
 public Integer totalCount {get;set;}
 public Integer rowIndex {get;set;}
 public List<Mileage_expense__c> delexpense {get; set;} 
 public addMileageExpense(ApexPages.StandardController controller) {
 
 reports = (Expense_Report__c)controller.getRecord();
 expenseList = [Select id, Name, Expense_Report__c, Miles__c, Total_Miles__c,   
                Date__c, Prgm_1_Miles__c, Prgm_2_Miles__c, Prgm_3_Miles__c, Prgm_4_Miles__c, 
                Prgm_5_Miles__c, Prgm_6_Miles__c from Mileage_expense__c where Expense_Report__c =: reports.ID];
 totalCount = expenseList.size();
 
 delexpenseList = new List<Mileage_expense__c>();
 delexpense = new List<Mileage_expense__c>();
 }
 
 public void addRow(){
 addexpenseList = new List<Mileage_expense__c>();
 expenseList.add(new Mileage_expense__c(Expense_Report__c = reports.Id));
 }
 
 public PageReference ave(){
 
 upsert expenseList;
 delete delexpenseList;
 return (new ApexPages.StandardController(reports)).view();
 } 
 
 public void deleteRow(){
 
 rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
 System.debug('row to be deleted ' + rowIndex );
 System.debug('row to be deleted '+ expenseList[rowIndex]);

     del = expenseList.remove(rowIndex);
     If(del.Id <> null) {delexpenseList.add(del);}
         
 
     }
 }
 
 
I am Getting this Error when i run/save the vf page:
Error: Cannot coerce from class core.apexpages.el.adapters.RuntimeTypeMetadataELAdapter to class java.lang.Boolean    

this is my vf code:
<apex:repeat value="{!mapkeys}" var="key">
<!--    <apex:column headerValue="{!key}"> </apex:column>-->
    
    <apex:dataTable value="{!mapprofile[key]}" var="v" width="30%" border="2">
 <apex:column value="{!v.SObjectType}"  headerValue="Sobject Name"/> 
             <apex:column value="{!v.PermissionsRead}" headerValue="Read"/>
             <apex:column value=" {!v.PermissionsCreate}" headerValue="Creat"/>
<apex:column value=" {!v.PermissionsEdit}" headerValue="Edit"/> 
<apex:column value=" {!v.PermissionsDelete}" headerValue="Delete"/>  
</apex:dataTable>
    
    
        <!--<apex:outputText value="{!yourMap[key]}"/> -->
    
</apex:repeat>

and i dont know how to clear this bug, i searched here and also i googled  but no luck , 
can any one quickly respond to my post please.

thanks in advance.