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
Marcelo AgostinhoMarcelo Agostinho 

VF Fields to Apex Class Parameters! How can i do it?

Hello guys! Im having some problems trying to find how can i pass a value from a field for an Apex Class parameter

 

For exemple

 

My simple VF Page.

 

 

<apex:page controller="ProcessDataLoad">

    <apex:form >

        <p>
            Actual Date (mm/aaaa)<apex:inputText id="actualDate"/>
        </p>
        
        <p>
            Month Quantity<apex:inputText id="qtdMonth"/>
        </p>
    
        <apex:commandButton value="Test"/>
    
    </apex:form>

</apex:page>

 And now i want to now how can i get these value in my Apex class when i click on commandButton?

 

 

Thanks for all!

 

 

Marcelo Agostinho

 

skodisanaskodisana

Hi,

 

You can use the <apex:param>  tag for sending the parameters from page to apex class.

 

For more information on this use the component reference from Visualforce page. 

 

 

<apex:param name="lName" value="{!contact.LastName}"/>

 

Thanks,

Kodisana

 

Marcelo AgostinhoMarcelo Agostinho

Sorry i read about <apex:param> but i dont understand how can i get the value from my inputField and set my apex:param tag value!

Imran MohammedImran Mohammed

Hi,

 

The variable that will be used in VF page should be declared in Controller class.

 

 

<apex:page controller="ProcessDataLoad">
    <apex:form >
        <p>
            Actual Date (mm/aaaa)<apex:inputText id="{!actualDate}"/>
        </p>
        
        <p>
            Month Quantity<apex:inputText id="{!qtdMonth}"/>
        </p>
    
        <apex:commandButton value="Test" action="{!controlerMethod}"/>
    
    </apex:form>
</apex:page>
Apex class
-------------------------------
public class ProcessDataLoad
{
 public Date actualDate {get; set;}
 public String qtdMonth {get; set;}
 public ProcessDataLoad()
 {
 //Do your stuff here;
 }
 
 public PageReference controllerMethod()
 {
 //when you access the actualDate and qtdMonth, they will have the values eneterd in VF page.
 
 }
}
Let me know if you have any questions.

 

Marcelo AgostinhoMarcelo Agostinho

What is this {get; set;} after. parameter declaration ? 

 

Very thanks for all the help!

Imran MohammedImran Mohammed

These are the getters and setters as per Apex documentation.

You can find more info on that in Apex documentation.