You need to sign in to do that
Don't have an account?
anuraj
Date search
I am serching for date in my code. But am am not able to get it please help me it is urgent. I am new to salesforce.
<apex:page controller="apposearchController" sidebar="false"> <apex:form > <apex:pageMessages id="errors" /> <apex:pageBlock title="Appoinment!" mode="edit"> <table> <tr> <td width="200" valign="top"> <apex:pageBlock title="Parameters" mode="edit" id="criteria"> <script type="text/javascript"> function doSearch() { searchServer( document.getElementById("AppoinmentType").value, document.getElementById("Clint").value, document.getElementById("StartDate").value, document.getElementById("Status").options[document.getElementById("Status").selectedIndex].value ); } </script> <script type="text/javascript" src="clear-default-text.js"></script> <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors"> <apex:param name="AppoinmentType" value="" /> <apex:param name="Clint" value="" /> <apex:param name="StartDate" value="" /> <apex:param name="Status" value="" /> </apex:actionFunction> <table cellpadding="2" cellspacing="2"> <tr> <td style="font-weight:bold;">Appoinment Type<br/> <input type="text" id="AppoinmentType" onkeyup="doSearch();" class="cleardefault"/> </td> </tr> <tr> <td style="font-weight:bold;">Clint<br/> <input type="text" id="Clint" onkeyup="doSearch();" class="cleardefault"/> </td> </tr> <tr> <td style="font-weight:bold;">Start Date<br/> <input type="text" id="StartDate" onkeyup="doSearch();" class="cleardefault"/> </td> </tr> <tr> <td style="font-weight:bold;">Status<br/> <select id="Status" onchange="doSearch();"> <option value=""></option> <apex:repeat value="{!Status}" var="tech"> <option value="{!tech}">{!tech}</option> </apex:repeat> </select> </td> </tr> </table> </apex:pageBlock> </td> <td valign="top"> <apex:pageBlock mode="edit" id="results"> <apex:pageBlockTable value="{!Appoinment}" var="Appointment"> <apex:column > <apex:facet name="header"> <apex:commandLink value="AppoinmentType" action="{!toggleSort}" rerender="results,debug"> <apex:param name="sortField" value="Appointment_Type__c" assignTo="{!sortField}"/> </apex:commandLink> </apex:facet> <apex:outputField value="{!Appointment.Appointment_Type__c}"/> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Clint" action="{!toggleSort}" rerender="results,debug"> <apex:param name="sortField" value="Client__c" assignTo="{!sortField}"/> </apex:commandLink> </apex:facet> <apex:outputField value="{!Appointment.Client__c}"/> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="StartDate" action="{!toggleSort}" rerender="results,debug"> <apex:param name="sortField" value="Start_Date__c" assignTo="{!sortField}"/> </apex:commandLink> </apex:facet> <apex:outputField value="{!Appointment.Start_Date__c}"/> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Status" action="{!toggleSort}" rerender="results,debug"> <apex:param name="sortField" value="Status__c" assignTo="{!sortField}"/> </apex:commandLink> </apex:facet> <apex:outputField value="{!Appointment.Status__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </td> </tr> </table> <apex:pageBlock title="Debug - SOQL" id="debug"> <apex:outputText value="{!debugSoql}" /> </apex:pageBlock> </apex:pageBlock> </apex:form> </apex:page>
public class apposearchController { public List<Appointment1__c> Appoinment{get;set;} private String soql {get;set;} public String technologies { get; set; } public String sortDir { get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; } set; } public String sortField { get { if (sortField == null) {sortField = 'Appointment_Type__c'; } return sortField; } set; } public String debugSoql { get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; } set; } public apposearchController() { //delete(soql); soql = 'select Appointment_Type__c, Client__c, Start_Date__c, Status__c, Client_First_Name__c from Appointment1__c where Client_First_Name__c!= null'; System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++Appoinment '+ Appoinment); System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++'+ soql ); runQuery(); } public void toggleSort() { sortDir = sortDir.equals('asc') ? 'desc' : 'asc'; runQuery(); } // public List<Appointment1__c> appo {get;set;} public String getStatus() { return null; } public void runQuery() { try { string a=soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; system.debug(a); Appoinment = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'); System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++contacts '+ Appoinment); } catch (Exception e) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!')); } } public PageReference runSearch() { String AppoinmentType; String Clint; string StartDate; String Status; AppoinmentType = Apexpages.currentPage().getParameters().get('AppoinmentType'); System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++AppoinmentType '+ AppoinmentType); Clint = Apexpages.currentPage().getParameters().get('Clint'); System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++Clint '+ Clint); // StartDate = Apexpages.currentPage().getParameters().get('StartDate'); // Datetime myDate = datetime.valueOf(StartDate); // System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++PaccountName '+ StartDate); // String technology = Apexpages.currentPage().getParameters().get('technology'); soql = 'select Appointment_Type__c, Client__c, Start_Date__c, Status__c, Client_First_Name__c from Appointment1__c where Client_First_Name__c != null'; if (!AppoinmentType.equals('')) soql += ' and Appointment_Type__c LIKE \''+String.escapeSingleQuotes(AppoinmentType)+'%\''; System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++AppoinmentType '+ AppoinmentType); if (!Clint.equals('')) soql += ' and Client_First_Name__c LIKE \''+String.escapeSingleQuotes(Clint)+'%\''; System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++Clint '+ Clint); // if (!myDate.equals('')) // soql += ' and Start_Date__c LIKE \''+Datetime.escapeSingleQuotes(myDate)+'%\''; // System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++accountName'+ StartDate); if (!Status.equals('')) soql += ' and Status__c includes (\''+Status+'\')'; System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++Status'+ Status); runQuery(); return null; } public List<String> Status { get { if (Status == null) { Status = new List<String>(); Schema.DescribeFieldResult field = Appointment1__c.Status__c.getDescribe(); for (Schema.PicklistEntry f : field.getPicklistValues()) Status.add(f.getLabel()); } return Status; } set; } }
This is how i did.
The problem is in :
if (!myDate.equals('')) soql += ' and Start_Date__c LIKE \''+Datetime.escapeSingleQuotes(myDate)+'%\''; System.debug('++++++++++++++++++++++++++++++++++++++++++++++++++++++++accountName'+ StartDate);
please help me
Thanks
Anuraj
Please help me
you can't use LIKE for comparing dates.
You probably want to use =
i am facing same problem if you get solution then help me.
thanx
I find out the solution for search records by date field. If You Want let me Know . :)