function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hugo StoupeHugo Stoupe 

Trying to pass a recordID to a controller - then to another controller.

I have a visualforce page that has a date input.  This page is embedded in a object page detail.

My goal is to have them select a date - click the button which takes them to a new pop-up window / visualforce page where they can enter time / hours.

Depending on which object the first visualforce page is embedded, I want to pass that objects recordID to the controller, but I am getting nothing - getting "null".  I have tried <apex:param and <apex:inputhidden and neither work.

The workflow is:
  •      PARENT OBJECT (CCI_project__c) has an embedded VF page called "terlproject"
  •      TERLPROJECT has a form with a date picker.  Once the button is clicked, the controller is "OpenTimeEntry"
  •      All OpenTimeEntry does is gather the parameters (date and objectID) and pass it to a new VF page called teGridView
  •      TEGRIDVIEW has a controller (teGridClass) that pulls data and populates the VF page "teGridView"

Can anyone help?  Below is screen shots and code:

1.  embedded visualforce page "terlProject"   In this case, It is on a custom object called "CCI_Project__C" and I am trying to pass the Date and REcord ID - the date is passing fine - the record ID is not (I display it on the VF page so I know the ID exists)
User-added image

The code for the Visualforce page is: 
<apex:page Standardcontroller="CCI_Project__c" extensions="openTimeEntry">
    <apex:form >
        <!-- Variables go here -->
        

        <!-- Input Buttons here -->
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <b>Date</b><apex:inputfield value="{!dum.dateOne__c}"/>
                <apex:inputHidden value="{!CCI_Project__c.ID}" id="projID"/>
               Project. <apex:outputField value="{!CCI_Project__c.id}"/>
                <apex:commandButton value="Enter Time" action="{!fetchPage}">
               <!-- <apex:param name="projID" value="{!CCI_Project__c.ID}" assignTo="{!projID}"/>-->
                </apex:commandButton>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    
    <!-- Related List Displays here -->



</apex:page>

Once clicked, I call the controller class "openTimeEntry" - you will see i have tried various ways of "getting" the ProjectID - but debug shows null.
public class openTimeEntry {
public dummyTable__c dum{get;set;}
public ID projID{get;set;}
public cci_Project__c co {get; set;}
private Date uDate; 

public openTimeEntry(ApexPages.StandardController controller) { 
    Date uDate = Date.valueOf(System.Now());
    dum=new dummyTable__c();
    System.debug('ProjID: '+projID);
    }

public PageReference fetchPage(){
      
      String testDate = String.valueof(dum.dateOne__c);
      if(testDate==null) {
          uDate = Date.today();
      }else{
          uDate = dum.dateOne__c; 
       }

              System.debug('openTimeEntryTestDate'+testDate);
              System.debug('openTimeEntrydumDate'+dum.dateOne__c);
              System.debug('openTimeEntryuDate'+uDate);
              System.debug('ProjectID----'+projID+co);
      
        pageReference teGridView = new PageReference('/apex/teGridView?uDate='+uDate+'&projectID='+projID);
        return teGridView ;
    
    }
 
  
}
Then I re-direct to the teGridView which has a controller class teGridClass

Here is the page, followed by the class.
<apex:page standardController="Time_Entry__c" extensions="teGridClass" sidebar="true">
 <apex:form >
 <apex:pageBlock title="Time Card" id="pb">
 <apex:pageMessages />
 <apex:variable var="rowNumber" value="{!0}"/>
            <!-- Debug - SQL statement -->
           <apex:pageBlockSection columns="1" title="DEBUG - Dynamic SOQL Query" collapsible="True">
                <apex:outputText value="{!query}">
                </apex:outputText>
               Date:  
                <apex:outputText value="{!tDate}">
                </apex:outputText>
               EmployeeID:  
                <apex:outputText value="{!tDate}">
                </apex:outputText>
            </apex:pageBlockSection>
 <apex:pageBlockSection title="Daily Time Entry" collapsible="false">
 Date:  <apex:outputText value="{!tDate}">
                </apex:outputText>
                
 Employee:  <apex:outputText value="{!tDate}">
                </apex:outputText>
 </apex:pageBlockSection>
 <apex:pageblockSection columns="1">
 <apex:pageBlockTable title="Time Card Entries" var="tce" value="{!TEList}"> 

 <apex:column headerValue="No." style="width:10px; 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="Functional Area" width="10px">
 <apex:inputField value="{!tce.Functional_Area__c}"/>
 </apex:column> 
 
 <apex:column headerValue="Activity Detail" width="10px">
 <apex:inputField value="{!tce.Description__c}"/>
 </apex:column> 
 <apex:column headerValue="Project" width="10px">
 <apex:inputField value="{!tce.Project__c}"/>
 </apex:column> 
 <apex:column headerValue="Contract" width="10px">
 <apex:inputField value="{!tce.Contract__c}"/>
 </apex:column> 
 <apex:column headerValue="Hours" width="5%">
 <apex:inputField value="{!tce.Total_Time__c}"/>
 </apex:column> 
 <apex:column headerValue="Date" width="10px">
 <apex:inputField value="{!tce.Date__c}"/>
 </apex:column> 
 

 
 <apex:column headerValue="Action" >
 <apex:commandButton value="Delete" action="{!deleteRow}" reRender="pb">
 <apex:param name="rowIndex" value="{!rowNumber}"/>
 </apex:commandButton>
 <apex:variable var="rowNumber" value="{!rowNumber+1}"/>
 </apex:column> 
 </apex:pageBlockTable>
 <apex:commandButton action="{!addRow}" value="Add Time" reRender="pb"/>
 </apex:pageblockSection>
 <apex:pageBlockButtons >
 <apex:commandButton value="Save" action="{!ave}" />
 <apex:commandButton value="Cancel" action="{!cancel}"/>
 </apex:pageBlockButtons>
 </apex:pageBlock>
 </apex:form> 
 </apex:page>
teGridClass:
public class teGridClass {
    public dummyTable__c dum{get;set;}
    public Time_Entry__c timecards {get;set;}
    public Time_Entry__c del;
    public List<Time_Entry__c> addTEList {get;set;}
    public List<Time_Entry__c> delTEList {get;set;}
    public List<Time_Entry__c> TEList {get;set;}
    public Integer totalCount {get;set;}
    public Integer rowIndex {get;set;}
    public String query{get;set;}
    Public Date tDate{get;set;}
    Private Date uDate{get;set;}
    Private String sDate;
 
    // Map of PageParameters
    private Map<string,string> urlParams=ApexPages.currentPage().getParameters();
 
    // Set the variable in Constructor

    public List<Time_Entry__c> delTEs {get; set;} 
 
    public teGridClass(ApexPages.StandardController controller) {
    
        if(urlParams.containsKey('uDate')){
            sDate = urlParams.get('uDate');
             }
            
        dum=new dummyTable__c();
               
        System.debug('tDate1'+tDate);
  
        tDate = dum.dateOne__c;
        System.debug('DateOne'+dum.DateOne__c);
        System.debug('tDate2'+tDate);
        System.debug('uDate'+uDate);
        System.debug('sDate'+sDate);

 // public teGridClass (ApexPages.StandardController controller) {
     timecards = (Time_entry__c)controller.getRecord();
 // String tID = timecards.ID;

    
     // Temp place Date value
         if(sDate==null) {            
      tDate = date.ValueOf(System.now());
         } else {
         tDate = date.ValueOf(sDate.substring(0,10));
        
         }
     
        String SobjectApiName = 'Time_Entry__c';
        Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();
 
        String commaSepratedFields = '';
        for(String fieldName : fieldMap.keyset()){
            if(commaSepratedFields == null || commaSepratedFields == ''){
                commaSepratedFields = fieldName;
            }else{
                commaSepratedFields = commaSepratedFields + ', ' + fieldName;
            }
        }
      query = 'select ' + commaSepratedFields + ' from ' + SobjectApiName + ' Where  Date__c=:tDate Limit 10';

     System.debug('query:'+query);
     System.debug('uDate:'+uDate);


 TEList = Database.query(query);

 totalCount = TEList.size();
 
 
 delTEList = new List<Time_Entry__c>();
 delTEs = new List<Time_Entry__c>();
 }
 
 public void addRow(){
 addTEList = new List<Time_Entry__c>();
 TEList.add(new Time_Entry__c(Date__c = dum.dateOne__c));
 }
 
 public PageReference ave(){
 
 upsert TEList;
 delete delTEList;
 return (new ApexPages.StandardController(timecards)).view();
 } 
 
 public void deleteRow(){
 
 rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
 System.debug('rowbe deleted ' + rowIndex );
 System.debug('rowm to be deleted '+TEList[rowIndex]);
 del = TEList.remove(rowIndex);
 delTEList.add(del);
 
 }
// }
 }





 
Best Answer chosen by Hugo Stoupe
Hugo StoupeHugo Stoupe
Although I tried this before and it didn't seem to work, I put in a rerender on the CommandButton and it seems to be working.

Final code that is working is:  VF Page:
<apex:page Standardcontroller="CCI_Project__c" extensions="openTimeEntry">
    <apex:form >
        <!-- Variables go here -->
        

        <!-- Input Buttons here -->
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <b>Date</b><apex:inputfield value="{!dum.dateOne__c}"/>
               <!--  Project. <apex:outputField value="{!CCI_Project__c.id}"/>-->
                <apex:commandButton value="Enter Time" action="{!fetchPage}" rerender="projID">
            <apex:param name="projID" value="{!CCI_Project__c.ID}" assignTo="{!projID}"/>
                </apex:commandButton>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    
    <!-- Related List Displays here -->



</apex:page>

Controller:
public class openTimeEntry {
public dummyTable__c dum{get;set;}
public ID projID{get;set;}
private Date uDate; 

public openTimeEntry(ApexPages.StandardController controller) { 
    Date uDate = Date.valueOf(System.Now());
    dum=new dummyTable__c();
    }

public PageReference fetchPage(){
      
      String testDate = String.valueof(dum.dateOne__c);
      if(testDate==null) {
          uDate = Date.today();
      }else{
          uDate = dum.dateOne__c; 
       }

              System.debug('openTimeEntryTestDate'+testDate);
              System.debug('openTimeEntrydumDate'+dum.dateOne__c);
              System.debug('openTimeEntryuDate'+uDate);
              System.debug('ProjectID----'+projID);
      
        pageReference teGridView = new PageReference('/apex/teGridView?uDate='+uDate+'&projectID='+projID);
        return teGridView; 
    }
}