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
Lahari KondadiLahari Kondadi 

Search criteria based on Date range FromDate to Todate

Hi experts,
                I am new to salesforce.I have a requirement where i need to provide search for FromDate and Todate on this range the closeDate should be displayed.I have tried as below but i am getting error.Please help.

 VF page
<apex:page Controller="GVWS_RegionCountry">

<apex:sectionHeader title="Reports" subtitle="Generate Report" id="sectionHeaderId"/>

 <apex:form id="ReportRegion">
    <apex:outputPanel id="msgPanel">
        <apex:pageMessages ></apex:pageMessages>
    </apex:outputPanel>
    <apex:pageblock id="pb">
    
        <apex:pageBlockSection id="SearchPanel" showHeader="true" columns="2">
            <apex:outputLabel value="Region"/>
            <apex:inputtext id="rname" value="{!region}"/>
            <apex:outputLabel value="Country"/>
            <apex:inputtext id="cname" value="{!country}" />
           <apex:outputLabel value="Close Date:"/>
           <br/>
               <apex:outputLabel value="From"/>
               <apex:inputtext id="cdfrom" value="{!fromDate}"/>
               <apex:outputLabel value="To"/>
               <apex:inputtext id="cdto" value="{!toDate}"/>
               
               
         
        </apex:pageBlockSection>      
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton action="{!displayReport}"  value="Generate Report" ID="ENTER_BUTTON"/>
        </apex:pageBlockButtons>
    </apex:pageblock>
    
    <apex:pageBlock id="pbb">
    <apex:pageBlockTable value="{!opportunityRecords}" var="opp">  >  
        <apex:column headerValue="Opportunity Name">{!opp.name}
        </apex:column> 
        <apex:column headerValue="Opportunity Owner">{!opp.owner.name}</apex:column>
        <apex:column headerValue="Region">{!opp.GEBRegion__c}</apex:column>
        <apex:column headerValue="Country">{!opp.Country__c}</apex:column>
        <apex:column headerValue="Broker/Partner">{!opp.Broker__c}</apex:column>
        <apex:column headerValue="Estimated Premium(Converted)"></apex:column>
        <apex:column headerValue="Close date">{!opp.CloseDate}</apex:column>
        <apex:column headerValue="Stage">{!opp.StageName}</apex:column>
        <apex:column headerValue="Created stage"></apex:column>
    </apex:pageBlockTable>

    </apex:pageblock>

 </apex:form>
</apex:page>

Controller
public class GVWS_RegionCountry 
{
  public String region{get;set;}
  public String country{get;set;}
  public String closeDate{get;set;}
  //public Date from{get;set;}
  public Date fromDate{get;set;}
  public Date toDate{get;set;}
  public List<Opportunity> opportunityRecords{get;set;}
  
   ApexPages.StandardSetController regionStandardSetController{get;set;}
  
  public GVWS_RegionCountry()
  {
    opportunityRecords = new list<Opportunity>();
    regionStandardSetController=new ApexPages.StandardSetController(new list<Opportunity>());
  
  }
  
   
 
   //List<Opportunity> reportQuery=new List<Opportunity>();
   //reportQuery='SELECT Id,Name,Owner,Broker__c,GVWS_Region__c,GVWS_Country__c ,CloseDate,StageName FROM Opportunity';
   String reportQuery1 ='SELECT Id,Name,Owner.Name,Broker__c,Country__c,GEBRegion__c,CloseDate,StageName FROM Opportunity WHERE StageName NOT IN (';
   String reportQuery2 = 'Ommitted';
   String reportQuery3 = 'Inforce';
   String reportQuery4 = 'Lost';
   String reportQuery5 = 'Declined';
   String reportQuery6 = ')';
   String reportQuery = reportQuery1+':'+'reportQuery2'+','+':'+'reportQuery3'+','+':'+'reportQuery4'+','+':'+'reportQuery5'+reportQuery6;
  
   
     
    
   public void displayReport()
 {
        String checkQuery = reportQuery;
        String checkInput = reportQuery;
        if(region!= null && !region.equalsIgnoreCase(''))
        {
          
            checkQuery = checkQuery + 'and GEBRegion__c like :region';
            system.debug('***********1'+checkQuery);
        }
        
        if(country!= null && !country.equalsIgnoreCase(''))
        {
         
            checkQuery = checkQuery + ' '+'and Country__c like :country';
            system.debug('***********2'+checkQuery);
        }
        
        if((fromDate!= null)&&(toDate!=null))
        {
          checkQuery=checkQuery+' '+'and (closeDate>=:fromDate AND closeDate<= :toDate+1)';
          system.debug('************3'+checkQuery);
        }
      
        if(checkQuery.equals(checkInput)){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Please Enter value in at least one search criteria'));
            opportunityRecords = new list<Opportunity>();
            return;
        }
      //   system.debug('***********1'+checkQuery);
      
       
       regionStandardSetController=new ApexPages.StandardSetController(Database.getQueryLocator(checkQuery));
       
        opportunityRecords= regionStandardSetController.getRecords();
        
}
      
}

Please help me with this.


Thanks & regards,
Lahari

 
Best Answer chosen by Lahari Kondadi
Lahari KondadiLahari Kondadi
Hi vickey,
        Thanks for the reply,
I just added type="date" in VF page.Now its working fine.
 
<apex:outputLabel value="Close Date:"/>
           <br/>
               <apex:outputLabel value="From"/>
               <apex:input id="cdfrom" value="{!fromDate}" type="date"/>
               <apex:outputLabel value="To"/>
               <apex:input id="cdto" value="{!toDate}" type="date"/>

Thanks & Regards,
Lahari

All Answers

Ravi Narayanan 2Ravi Narayanan 2

Hi Lahari,

What is the error which you are getting ? please explain that so that its easy to debug based on that.

Thanks,

Ravi Narayanan

Lahari KondadiLahari Kondadi
Hi Ravi,
    Thanks for your quick reply.
I am getting below error
Value 'Sun Nov 22 00:00:00 GMT 2015' cannot be converted from Text to com.force.swag.soap.DateOnlyWrapper
Value 'Wed Dec 02 00:00:00 GMT 2015' cannot be converted from Text to com.force.swag.soap.DateOnlyWrapper


In from date field i have given  Sun Nov 22 00:00:00 GMT 2015 and in to date field i have given Wed Dec 02 00:00:00 GMT 2015 value. i dont know how to sort it out.
Please help

Thanks,
Lahari
Waqar Hussain SFWaqar Hussain SF
Use this code in your controller, Not tested but it will work fine for you. 
public class GVWS_RegionCountry 
{
  public String region{get;set;}
  public String country{get;set;}
  public String closeDate{get;set;}
  //public Date from{get;set;}
  public String fromDate{get;set;}
  public String toDate{get;set;}
  public List<Opportunity> opportunityRecords{get;set;}
  
   ApexPages.StandardSetController regionStandardSetController{get;set;}
  
  public GVWS_RegionCountry()
  {
    opportunityRecords = new list<Opportunity>();
    regionStandardSetController=new ApexPages.StandardSetController(new list<Opportunity>());
  
  }
  
   
 
   //List<Opportunity> reportQuery=new List<Opportunity>();
   //reportQuery='SELECT Id,Name,Owner,Broker__c,GVWS_Region__c,GVWS_Country__c ,CloseDate,StageName FROM Opportunity';
   String reportQuery1 ='SELECT Id,Name,Owner.Name,Broker__c,Country__c,GEBRegion__c,CloseDate,StageName FROM Opportunity WHERE StageName NOT IN (';
   String reportQuery2 = 'Ommitted';
   String reportQuery3 = 'Inforce';
   String reportQuery4 = 'Lost';
   String reportQuery5 = 'Declined';
   String reportQuery6 = ')';
   String reportQuery = reportQuery1+':'+reportQuery2+','+':'+reportQuery3+','+':'+reportQuery4+','+':'+reportQuery5+reportQuery6;
  
   
     
    
   public void displayReport()
 {
        String checkQuery = reportQuery;
        String checkInput = reportQuery;
        if(region!= null && !region.equalsIgnoreCase(''))
        {
          
            checkQuery = checkQuery + 'and GEBRegion__c like :region';
            system.debug('***********1'+checkQuery);
        }
        
        if(country!= null && !country.equalsIgnoreCase(''))
        {
         
            checkQuery = checkQuery + ' '+'and Country__c like :country';
            system.debug('***********2'+checkQuery);
        }
        
        if((fromDate!= null)&&(toDate!=null))
        {
        	Date fromDate_d = date.valueOf(fromDate);
        	Date toDate_d = date.valueOf(toDate);
          checkQuery=checkQuery+' '+'and (closeDate>=:fromDate_d AND closeDate<= :toDate_d+1)';
          system.debug('************3'+checkQuery);
        }
      
        if(checkQuery.equals(checkInput)){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Please Enter value in at least one search criteria'));
            opportunityRecords = new list<Opportunity>();
            return;
        }
      //   system.debug('***********1'+checkQuery);
      
       
       regionStandardSetController=new ApexPages.StandardSetController(Database.getQueryLocator(checkQuery));
       
        opportunityRecords= regionStandardSetController.getRecords();
        
}
      
}

 
Lahari KondadiLahari Kondadi
Hi vickey,
        Thanks for the reply,
I just added type="date" in VF page.Now its working fine.
 
<apex:outputLabel value="Close Date:"/>
           <br/>
               <apex:outputLabel value="From"/>
               <apex:input id="cdfrom" value="{!fromDate}" type="date"/>
               <apex:outputLabel value="To"/>
               <apex:input id="cdto" value="{!toDate}" type="date"/>

Thanks & Regards,
Lahari
This was selected as the best answer