+ Start a Discussion
Eager-2-LearnEager-2-Learn 

How to feed date ranges to a query via VF page

Hi,

 

Does anyone have some jump-start code for the following requirement.

 

I want to have a VF page that contains two date fields.  The user will select a date range and click ok.


Those two field values must feed a query that will pull all opportunities within that date range.

 

I will do some logic (I can handle this, I hope) to build two lists from the initial results produced from above.

 

I will produce a final number that I want to display on that same VF page below the two fields.

 

The result is that I want to have this VF page on a dashboard so that the user can dynamically get the final number.

 

 

In Summary:

pass to field values on vf page to apex class

include those values in the query dynamically

return a value to the same vf page

 

 

Is this possible and does anyone have any subset of starter code for such a task?

 

 

 

The final number that I want cannot be derived from SFDC reports because I am trying to get the ratio of what two fields that are text fields.  One field is sold and the other is offered.   I am focusing on a single product that is offered but not sold.  These fields are multi-picklists so I figured I would have to do something like I am asking above as a work-around.

Best Answer chosen by Admin (Salesforce Developers) 
vanessenvanessen

on your VF page you can design two fields .lets escape the part that you are using js script to validate a date etc...

 

in vf :

<apex:outputPanel id="showdate">

<apex: inputText value="{!date1}" />

<apex: inputText value="{!date2}" />

<apex:commandButton value="go" reRender="showme" action="{!OppCalc}"/>     

</apex:outputPanel>

 

<apex:outputPanel id="showme">

<apex:outputText value="{!val1}" />

</apex:outputPanel>

 

 

in apex contyroller:

 

public String date1{get;set;}

public String date2{get;set;}

public Double val1{get;set;}

 

//skipping the constructor part etc...

//in your contructor ,you should make val1 = null;

 

public Void getOppCalc(){

 

//need to convert the date1 and date2 to date format using the split function and the Date.newInstance() method

 

list<Opportunity> oppList = [select ...... from Opportunity where createdDate > date1 and createdDate < date2];

//the select is just for an idea ,you have to arrange it to suit your need

 

...do you calculation things etc...

 

//set the value for val1

 

val1 = .... ;

}