0

I have a parameter that is always giving me a null value. I tried the assignto tag, to no avail, now I am trying to retrieve the parameters. I am still getting a null value.

Attached below is the apex class and the VF code.

<apex:pageBlockTable id="ORDER_TABLE" value="{!ordList}" var="ord" style="table">
<apex:column >
<apex:facet name="header">Order Name</apex:facet>
<apex:outputText value="{!ord.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Order Date</apex:facet>
<apex:outputText value="{!ord.OrdDateTime__c}"/>
 </apex:column>
<apex:column >
<apex:facet name="header">Order Total</apex:facet>
<apex:outputText value="{!ord.Order_Total__c}"/>
</apex:column>
 <apex:column >
<apex:facet name="header">Status</apex:facet>
<apex:outputText value="{!ord.Status__c}"/>
</apex:column>
<apex:column >
//This is the important section
<apex:facet name="header">Order Details</apex:facet>
<apex:commandButton id="ordDetails" value="Details" action="{!getDetails}" rerender="out">
     <apex:param name="date" value="{!ord.OrdDateTime__c}" assignTo="{!orderDate}"/>
 </apex:commandButton>
 </apex:column>
</apex:pageBlockTable>
//The important section ends here
<apex:commandButton action="{!getUserOrders}" rerender="ORDER_TABLE" value="GET MY LIST!" />


  </apex:pageBlock>
</apex:form>
<apex:form >
          <apex:outputpanel id="out">
             <apex:pageBlock >
               <apex:pageBlockTable id="Detail_Order" value="{!detOrd}" var="det" style="table">
               <apex:column >
                <apex:facet name="header">Order Name</apex:facet>
                <apex:outputText value="{!det.ItemSKU__c}"/>
               </apex:column>
               <apex:column >
                <apex:facet name="header">Order Date</apex:facet>
                <apex:outputText value="{!det.ItemDescription__c}"/>
               </apex:column>
               <apex:column >
                <apex:facet name="header">Order Total</apex:facet>
                <apex:outputText value="{!det.Quantity__c}"/>
               </apex:column>
               </apex:pageBlockTable>
               </apex:pageBlock>
          </apex:outputpanel>

APEX

    public List<UserOrder__c> ordList {get; set;}
    public List<Order__c> detOrd {get; set;}
    public String orderDate {get; set;}

    public void getUserOrders() {
    String userName = UserInfo.getUserID();
    List<UserOrder__c> ords = [
               select Name, UserID__c, OrdDateTime__c, Order_Total__c, Status__c
               from UserOrder__c
               where UserID__c =: userName
               ];
       // Pass out the value
       ordList = ords;
     }
   //This is the important section
    public void getDetails() {
    System.debug('kutta');
    String userName = UserInfo.getUserID();
    orderDate = ApexPages.currentPage().getParameters().get('date')
    System.debug(orderDate); //this is null
    List<Order__c> ord = [
               select UserID__c, ItemSKU__c, ItemDescription__c, Quantity__c
               from Order__c
               where USERID__c =: userName 
               ];

          detOrd = ord;
    }
    //Important section ends here
1
  • 1
    You need to expose whole code so we can see where and how your variables are initialized etc.
    – Eduard
    Commented Jul 12, 2018 at 8:23

2 Answers 2

0

Please consider the below points

  • Create a Property in Apex class with get; set;
  • Use assignTo to pass the value from the command button
  • Use that parameter in Apex Class
    Refer below Link
    Passing Parameters Commandbutton
0
  1. orderDate gets assigned only here (as I can see from the code given)

    orderDate = ApexPages.currentPage().getParameters().get('date');

which means if your URL doesn't get a value for this parameter, the get('date') will return null.

  1. You don't retrieve OrdDateTime__c in the SOQL, so no value will be assigned to orderDate. Do you use the same query to populate values for ordList?

  2. Use the assignTo="{! orderDate }" attribute in your apex:param tag to assign

--UPDATE--

You need to use apex:actionFunction in order to assign a value for your parameter. See the example code below.

Visualforce page testPage.vfp

<apex:page controller="testController">
    <apex:form id="testForm">
        <apex:pageBlock>
            <apex:pageBlockTable value="{! accounts }" var="acc" style="table">
                <apex:column value="{! acc.Id }"/>
                <apex:column >
                    <apex:facet name="header">Account Creared Date</apex:facet>
                    <apex:outputText value="{! acc.CreatedDate }"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">Account Details</apex:facet>
                    <!-- Option 1 USER_DEBUG [13]|DEBUG|accDate=Wed Jun 13 09:15:06 GMT 2018 -->
                    <button type="button" onclick="getDetails('{! acc.CreatedDate }');">Details (1)</button>
                    &nbsp;&nbsp;
                    <!-- Option 2 USER_DEBUG [13]|DEBUG|accDate=null -->
                    <apex:commandButton value="Details (2)" action="{! getDetails }" rerender="testForm">
                        <apex:param name="date" value="" assignTo="{! orderDate }"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:actionFunction name="getDetails" action="{! getDetails }" rerender="testForm">
            <apex:param name="date" value="" assignTo="{! accDate }"/>
        </apex:actionFunction>
    </apex:form>
</apex:page>

Apex controller testController.apxc

public class testController
{
    public List<Account> accounts {get; set;}
    public String accDate {get; set;}

    public testController()
    {
        accounts = [SELECT Id, Name, CreatedDate FROM Account];
    }

    public void getDetails()
    {
        System.debug('accDate=' + accDate);
    }
}
7
  • I have a debug statement around the variable and I get a null value still
    – R83nLK82
    Commented Jul 12, 2018 at 8:26
  • The debug statement doesn't impact anything. The fact is ApexPages.currentPage().getParameters().get('date') doesn't return a value, because the "date" parameter is either missing or empty. You need to assign a value to the orderDate in you Visualforce page using assignTo="{! orderDate }" statement. Also you can use apex:inputText to assign value to you orderDate. Finally you can initialize this variable in the Controller itself. So decide where you need orderDate to be assigned a value and use an appropriate approach.
    – Eduard
    Commented Jul 12, 2018 at 8:49
  • I have added the assignTo statement in the visualforce page, that still gives me a null value.
    – R83nLK82
    Commented Jul 12, 2018 at 9:00
  • Do you see any value on your page in the table for <apex:outputText value="{!ord.OrdDateTime__c}"/>?
    – Eduard
    Commented Jul 12, 2018 at 9:04
  • Yes I see Thu Jul 12 09:02:48 GMT 2018
    – R83nLK82
    Commented Jul 12, 2018 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .