0

I am trying to get the value that user enters for the Start Date and Team Name fields into the Extension class as mentioned below but i am getting Null. Could someone please help.

VF page:

<apex:page standardController="Tracker__c" extensions="TrackerExtension">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="View Details">
                <apex:inputField label="Start Date" required="true" value="{!Tracker__c.Sprint_Start_Date__c}" id="DatefieldVal" /> 
                <apex:inputField label="Team Name" required="true" value="{!Tracker__c.Team_Names__c}" id="TeamfieldVal"/>
            </apex:pageBlockSection>
        </apex:pageblock>
    </apex:form>
<apex:page> 

Extension Class:

public with sharing class TrackerExtension {
    public Date DatefieldVal {get;set;}
    public String TeamfieldVal {get;set;}


    public TrackerExtension(ApexPages.StandardController controller) {

    system.debug('ssDate'+ ApexPages.currentPage().getParameters().get('DatefieldVal'));
    system.debug('team'+ApexPages.currentPage().getParameters().get('TeamfieldVal'));

    }
    }
  • 1
    Welcome to SFSE! Please use the {} tool in the editor to format your code so contributors can read it, and make sure to only use relevant tags - this question is not related to community or salesforce1-app. – David Reed Jun 2 '19 at 15:18
  • Thanks @DavidReed, could you suggest me which tags to use to get answer for my question. – Nag Jun 2 '19 at 15:22
  • I have tagged your question apex, visualforce, and controller-extension, which seems to me to sum up what you are working with. – David Reed Jun 2 '19 at 15:23
5

The ApexPages.currentPage().getParameters() call allows you to access URL parameters supplied to your page. It has nothing to do with values bound to components on your page.

Your input fields are bound to field values on the object instance Tracker__c that is managed by the standard controller:

<apex:inputField label="Start Date" required="true" value="{!Tracker__c.Sprint_Start_Date__c}" id="DatefieldVal" /> 
<apex:inputField label="Team Name" required="true" value="{!Tracker__c.Team_Names__c}" id="TeamfieldVal"/>

Your constructor receives a reference to the standard controller:

public TrackerExtension(ApexPages.StandardController controller) {

which it is typical to save in an instance variable, e.g.,

private ApexPages.StandardController controller; 
public TrackerExtension(ApexPages.StandardController controller) {
    this.controller = controller;
}

Then, in your action methods, you can access the record managed by the standard controller by calling controller.getRecord(). You probably won't be doing this in your constructor, however, as the user will not have had a chance to interact with the page and populate any values at this point.

Note that while you can give Ids to your components in Visualforce, your server-side controller access is through value binding. You won't make calls based on the component Id in Apex to access their values, as you might when working in client-side JavaScript.

| improve this answer | |
  • If i want to capture the dynamic data that the user enters like in a form what changes do i need to make in my code so that i will be able to retrieve the values into the extension class. I also have an option of capturing these field values after clicking Submit button, could i use a method for Submit in which i can access the field values. – Nag Jun 2 '19 at 15:38
  • Yes. You need to do as I mention above: capture the standard controller and access its instance of the record with getRecord(). – David Reed Jun 2 '19 at 15:50
  • Thanks it is working. – Nag Jun 2 '19 at 16:25
  • 1
    @Nag if this answer solved your issue please consider marking it as accepted. It will reward the poster and yourself and indicate the question has a useful answer for others with similar issue – Eric Jun 2 '19 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.