+ Start a Discussion
K@SK@S 

between two dates get the all records start date and end date using search functionallty

Hi Team,
I got the errors, please help on this.
Apex class
[Error] Error: Compile Error: Variable does not exist: Start_Date__c at line 11 column 11
public class searchClientVisits{   
    List<Client_Visit__c> clientVisitList {get;set;}
    public Client_Visit__c clientInfo { get;set; }
    
    public SearchClientVisits(){  
     clientInfo  = new Client_Visit__c ();
    }
    
     public PageReference runSearch(){
       string query='SELECT Id,Start_Date__c,End_Date__c FROM Client_Visit__c WHERE CloseDate < LAST_FISCAL_QUARTER';
       if(Start_Date__c == strtdate && End_date__c == enddate){
             
      }
      clientVisitList =database.query(query);
   }
     public PageReference reset(){
        PageReference pg = new PageReference(System.currentPageReference().getURL());
        pg.setRedirect(false);
        return pg;
    }
}

VF page
[Error] Error: Unknown property 'void.Start_Date__c'

<apex:page controller="searchClientVisits">
    <apex:form>
        <apex:pageBlock>
        <apex:pageBlockSection >
        <apex:inputField value="{!clientInfo.Start_Date__c}" label="Start Date"/>
        <apex:inputField value="{!clientInfo.End_Date__c }" label="End Date"/>
        </apex:pageBlockSection>

    <apex:pageBlockButtons >
    <apex:commandButton value="Reset" action="{!reset}"/>
    <apex:commandButton value="Search" action="{!runSearch}"/>
    </apex:pageBlockButtons>
    </apex:pageBlock>

    <apex:pageBlock >
    <apex:pageBlockTable value="{!clientVisitList }" var="client" id="clientList">
    <apex:column value="{!client.Start_Date__c}" headerValue="Start Date"/>
    <apex:column value="{!client.End_Date__c }" headerValue="End Date"/>
   </apex:pageBlockTable>
   
  </apex:pageBlock>
</apex:form>
</apex:page>
Best Answer chosen by K@S
ManojjenaManojjena
Kae,

Try with below code ,
 
if(clientInfo.Start_Date__c != null & clientInfo.End_Date__c != null){
	   Date startDate=clientInfo.Start_Date__c;
	   Date endDate=clientInfo.End_Date__c ;
	   string query='SELECT Id,Accounts__c,Start_Date__c,End_Date__c FROM Client_Visit__c WHERE Start_Date__c =:'+startDate+' AND End_Date__c=:'+endDate;
   }

 

All Answers

ManojjenaManojjena
HI Kae,

Problem in this line  if(Start_Date__c == strtdate && End_date__c == enddate)

Could you please explain your requirment bit more so that we can help you .
K@SK@S
Hi Manjo,
whenever enter the start date and end date then click search button after retrive all records in  between dates.
I changed this like
 public PageReference runSearch(){
       string query='SELECT Id,Accounts__c,Start_Date__c,End_Date__c FROM Client_Visit__c WHERE CloseDate < LAST_FISCAL_QUARTER';
       if(clientInfo.Start_Date__c<System.Today() && clientInfo.End_Date__c >System.Today()){
      }
Error: Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 15 column 7
but VF same error will be there
Thanks,
kae
ManojjenaManojjena
Hi kae,

Do you want to add three filter in your query like within  startdate and end date , closeDate should less then last quarter ?
You have missed one thing you need to return null or some thing from that method 

Please confirm .Also your start date and end date are DateTime or Date only ?
ManojjenaManojjena
Kae,

Try with below code ,
 
if(clientInfo.Start_Date__c != null & clientInfo.End_Date__c != null){
	   Date startDate=clientInfo.Start_Date__c;
	   Date endDate=clientInfo.End_Date__c ;
	   string query='SELECT Id,Accounts__c,Start_Date__c,End_Date__c FROM Client_Visit__c WHERE Start_Date__c =:'+startDate+' AND End_Date__c=:'+endDate;
   }

 
This was selected as the best answer
ManojjenaManojjena
HI Kae,
Change your method liek below and let me know if it helps !!
public PageReference runSearch(){
		if(clientInfo.Start_Date__c != null & clientInfo.End_Date__c != null){
			Date startDate=clientInfo.Start_Date__c;
			Date endDate=clientInfo.End_Date__c ;
			string query='SELECT Id,Accounts__c,Start_Date__c,End_Date__c FROM Client_Visit__c WHERE Start_Date__c =:'+startDate+' AND End_Date__c=:'+endDate;
			clientVisitList =database.query(query);
		}
   }

 
ManojjenaManojjena
add return null before ending brace of method .
ManojjenaManojjena
Hi Kae,

Try with below cod eit will help !!
public class searchClientVisits{   
    public List<Client_Visit__c> clientVisitList {get;set;}
    public Client_Visit__c clientInfo { get;set;}
    public SearchClientVisits(){  
        clientInfo  = new Client_Visit__c ();
            clientVisitList =new List<Client_Visit__c>();
    }
    public PageReference runSearch(){
            clientVisitList.clear();
        if(clientInfo.Start_Date__c != null & clientInfo.End_Date__c != null ){
            String startDate=String.valueOf(clientInfo.Start_Date__c).left(10);
            String endDate=String.valueOf(clientInfo.End_Date__c).left(10);
            String querystr='SELECT Id,Start_Date__c,End_Date__c,Accounts__c,Clients__c FROM Client_Visit__c WHERE Start_Date__c ='+startDate+' AND End_Date__c='+ endDate;
            clientVisitList = Database.query(querystr);
        }
        return null;
    }
    public PageReference reset(){
        PageReference pg = new PageReference(System.currentPageReference().getURL());
        pg.setRedirect(false);
        return pg;
    }
}

//////////////////////////////////////////////

<apex:page controller="searchClientVisits" id="pg">
    <apex:form id="frm">
        <apex:pageBlock id="pgblk1">
            <apex:pageBlockSection id="pgblksec">
                <apex:inputField value="{!clientInfo.Start_Date__c}" label="Start Date"/>
                <apex:inputField value="{!clientInfo.End_Date__c }" label="End Date"/>
            </apex:pageBlockSection>
        <apex:pageBlockButtons >
            <apex:commandButton value="Reset" action="{!reset}"/>
            <apex:commandButton value="Search" action="{!runSearch}" reRender="clientList"/>
        </apex:pageBlockButtons>
        </apex:pageBlock>
        <apex:pageBlock id="pgblk">
            <apex:pageBlockTable value="{!clientVisitList}" var="cl" id="clientList">
				<apex:column value="{!cl.Accounts__c}" headerValue="Account Name"/>
				<apex:column value="{!cl.Clients__c}" headerValue="Clients"/>			
				<apex:column value="{!cl.Start_Date__c}" headerValue="Start Date"/>
				<apex:column value="{!cl.End_Date__c}" headerValue="End Date"/>
			</apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Let me know if it helps !!
Thanks 
Manoj
ManojjenaManojjena
Hi Kae ,

Try with belwo class code it wil help 
 
public class searchClientVisits{   
    public List<Client_Visit__c> clientVisitList {get;set;}
    public Client_Visit__c clientInfo { get;set;}
    public SearchClientVisits(){  
        clientInfo  = new Client_Visit__c ();
            clientVisitList =new List<Client_Visit__c>();
    }
    public PageReference runSearch(){
            clientVisitList=new List<Client_Visit__c>();
        if(clientInfo.Start_Date__c != null & clientInfo.End_Date__c != null ){
            String startDate=String.valueOf(clientInfo.Start_Date__c).left(10);
            String endDate=String.valueOf(clientInfo.End_Date__c).left(10);
            String querystr='SELECT Id,Start_Date__c,End_Date__c,Accounts__c,Clients__c FROM Client_Visit__c WHERE Start_Date__c ='+startDate+' AND End_Date__c='+ endDate;
            clientVisitList = Database.query(querystr);
        }
        return null;
    }
    public PageReference reset(){
        PageReference pg = new PageReference(System.currentPageReference().getURL());
        pg.setRedirect(false);
        return pg;
    }
}

 
K@SK@S
Hi Manoj,
Thank you very munch youe help.
I got the out put this like I has been changed.
    //search the client records
    public void runSearch(){
        if(clientInfo.Start_Date__c != null && clientInfo.End_Date__c != null){
            Date startDate=clientInfo.Start_Date__c;           
            Date endDate=clientInfo.End_Date__c;              
            clientvisitList = [SELECT Id,Accounts__c,Start_Date__c,End_Date__c,Clients__c,Locations__c  FROM Client_Visit__c  WHERE Start_Date__c <= :startDate AND End_Date__c >=:endDate];
            System.debug('#####'+clientvisitList);     
        }       
    }
  
Thanks,
kae