+ Start a Discussion
Matt FolgerMatt Folger 

Creating a date range in a front-end / back-end user driven query page

Hi, a while ago I created a page that took user inputted query criteria and 'routed' it to a back end controller that would load the query results.  I created the date ranges that the users wanted via the following code:
public List<SelectOption> getInquiryStatusDate (){
List<SelectOption> options = new List<SelectOption>();
//options.add(new SelectOption('-- Select Inquiry Status --', ''));
//options.add(new SelectOption('180', 'None'));
options.add(new SelectOption('All', 'All'));
options.add(new SelectOption('10', 'Last 10 days'));
options.add(new SelectOption('30', 'Last 30 days'));
options.add(new SelectOption('60', 'Last 60 days'));
options.add(new SelectOption('90', 'Last 90 days'));
return options;
These are easy to do because I only have to provide a single field for the user to manipulate in order to get the date ranges they want.  
queryString = 'SELECT name, Inquiry__c, Inquiry_Status__c, Product__c, PO__c, Vendor__c, Created_Date__c, Customer__c, CreatedBy.Lastname, Vendor_Response__c'+
                                 ' FROM Vencorr__c';
The querystring 'builder'.
if (Ven_CreatedDate != null && Ven_CreatedDate!= '' && Ven_CreatedDate!= 'None' && Ven_CreatedDate!= 'All'){
                string tempVen_Created_Date = Ven_CreatedDate;
                tempVen_Created_Date = String.escapeSingleQuotes(tempVen_Created_Date); //To avoid SOQL injection
                queryString += whereOrAndClause() + ' CreatedDate = LAST_N_DAYS: '+Ven_CreatedDate;
            }
The code that builds the date range criteria of the query string.

But the users are now wanting a date range field where they can select the upper and lower date range.  I'm not sure how to do that, I presume I've got to create 2 date variable strings, then combine them together and then feed that into the SOQL query that's being built on the backend