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
hari azmeera 8hari azmeera 8 

search a record by name, within a date range, starts with a particular word, contains a particular word in visualforce

Best Answer chosen by hari azmeera 8
Balaji B 10Balaji B 10
for above code

All Answers

AnjithKumarAnjithKumar
Dear Hari,

Please look into following link where Jeff explained Dynamic queries with example.

http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/


Hope it helps you.

Thanks,
Anjith kumar.
DeepthiDeepthi (Salesforce Developers) 
Hello Hari,

Please check the below similar sample code that meets your requirement.
 
<!-- VISUALFORCE PAGE-->
<apex:page controller="Controller" docType="html-5.0">
<apex:form >
    <apex:pageBlock title="Search for a record">
        <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
                <apex:outputLabel >First Name</apex:outputLabel>
                <apex:inputText value="{!name}"/>    
            </apex:pageBlockSectionItem><br/>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >Start Date</apex:outputLabel>  
                <apex:inputText value="{!sd}"/>  
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel >End Date</apex:outputLabel>  
                <apex:inputText value="{!ed}"/>  
            </apex:pageBlockSectionItem><br/>
            <apex:pageBlockSectionItem >
                <apex:commandButton value="Fetch" action="{!fetchValues}"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pageBlock >
        <apex:pageBlockTable var="cnd" value="{!C}">
            <apex:column headerValue="Candidate Number">
                <apex:outputText value="{!cnd.Name}"></apex:outputText>
            </apex:column>
            <apex:column headerValue="First Name">
                <apex:outputText value="{!cnd.First_Name__c}"></apex:outputText> 
            </apex:column>
            <apex:column headerValue="Last Name">
                <apex:outputText value="{!cnd.Last_Name__c}"></apex:outputText>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>
 
// Controller Class
public class Controller {

    public Date ed { get; set; }
    public Date sd { get; set; }
    public String name { get; set; }
    public List<Candidate__c> C {get;set;} 
    public Controller(){      
        C= new List<Candidate__c>(); 
    }
    public PageReference fetchValues() {
           
         C=[select Name, First_Name__c, Last_Name__c from Candidate__c where (First_Name__c like:name) AND (First_Name__c like:name+'%') AND (First_Name__c like:'%'+name+'%')AND (Start_Date__c>=:sd) AND (End_Date__c<=:ed)];
        return null;
    }
}
Hope this helps you!

Best Regards,
Deepthi

 
JyothsnaJyothsna (Salesforce Developers) 
Hi Hari,

Please check the below sample code.

VisualForce Page:
<apex:page controller="DateRangeCont">
 <apex:form id="dt1">
 <apex:pageBlock >
 <apex:pageBlockSection >
 <apex:pageBlockSectionItem >
 <apex:outputLabel >Start Date</apex:outputLabel>
 <apex:inputfield value="{!a.From_Date__c}"/>
</apex:pageBlockSectionItem>
 <apex:pageBlockSectionItem >
 <apex:outputLabel >End Date</apex:outputLabel>
 <apex:inputField value="{!a.To_Date__c}"/>
 </apex:pageBlockSectionItem>
  
<apex:commandButton value="Go" action="{!go}" reRender="dt"/>
 
</apex:pageBlockSection>
 <apex:pageBlockTable value="{!customer1}" var="ct" id="dt">
<apex:column headerValue="Customer Name">
<apex:inputField value="{!ct.Name}"/>
</apex:column>
<apex:column headerValue="billing city">
  <apex:inputField value="{!ct.Billing_City__c}"/>
  </apex:column>
  <apex:column value="{!ct.createddate}"/> 
  <apex:column headerValue="billing postal code">
  <apex:inputField value="{!ct.Billing_Postal_Code__c}"/>
  </apex:column>
</apex:pageBlockTable>
  
</apex:pageBlock>
 </apex:form>
</apex:page>

Controller:
 
public with sharing class DateRangeCont {

    public list<customer__c> customer1 { get; set; }
    
    public datetime startdate1;
    public datetime enddate1;
   public customer__c a { get; set; } 
    public DateRangeCont(){
     customer1=new list< customer__c>();
    a=new customer__c();
     
    }
    public PageReference go() {
    startdate1=a.From_Date__c;
    enddate1=a.To_Date__c;
    customer1=[select name,Billing_City__c ,Billing_Postal_Code__c,Createddate from customer__c where Createddate>=:startdate1 AND Createddate<=:enddate1];
    return null;
    }


    
}

Hope this helps you!
Best Regards,
Jyothsna
Balaji B 10Balaji B 10
Hello Hari,

Please check the below similar sample code that meets your requirement.

<!--------Vf page------->

<apex:page controller="sd_se" sidebar="false">
 <apex:form id="dt">
  <apex:pageBlock title="Job Details To Search">
  
        
     <!---search By Date Range-->
    Start Date<apex:inputField value="{!j.From_date__c}"/>&nbsp;&nbsp;&nbsp;
     End Date<apex:inputField value="{!j.To_date__c}"/>
     <apex:commandButton value="Go" action="{!go}" reRender="dt"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     
     <!---search By word-->
      <apex:inputText value="{!keyword}"/>
      <apex:commandButton value="Search By Word" action="{!getKey_search}"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     
     
      <!---search By Id-->
      <apex:inputtext value="{!Id}"/>
      <apex:commandButton value="Search By ID" action="{!getid}"/>
     
     <!---which fiels we want to display -->
   <apex:pageBlockSection columns="1">
   <apex:pageBlockTable var="jj" value="{!jb}">
    <apex:column headerValue="Name" value="{!jj.Name}"/>
     <apex:column headerValue="Experience" value="{!jj.Experience__c}"/>
      <apex:column headerValue="Required skills" value="{!jj.Required_skills__c}"/>
       <apex:column headerValue="salary" value="{!jj.salary__c}"/>
        <apex:column headerValue="Record Id" value="{!jj.id}"/>
      <apex:column headerValue="Start Date" value="{!jj.From_date__c}"/>
     <apex:column headerValue="End Date" value="{!jj.To_date__c}"/>
    </apex:pageBlockTable>
   </apex:pageBlockSection>
  </apex:pageBlock>
 </apex:form>
</apex:page>
 
Balaji B 10Balaji B 10
Business Class:

public with sharing class sd_se {

    public job__c j { get; set; }
    
    public String Id { get; set; }
    public List<job__c> jb { get; set; }
    public String keyword { get; set; }
   
   //Dc 
    public sd_se(){
     jb=new List<job__c>();
    j=new job__c();
}

    public PageReference getid() {
    jb=[select Name,id,Experience__c,Required_skills__c,Salary__c,From_date__c,To_date__c from job__c where id=:id limit 1];
        return null;
    }

     public PageReference getKey_search() {
    jb=(list<job__c>) [FIND:keyword IN ALL FIELDS RETURNING job__c(Name,id,Experience__c,Required_skills__c,Salary__c,From_date__c,To_date__c)][0];
        return null;
    }

//we need to assign some temp var,for data type
       public date startdate1;
       public date enddate1;
public PageReference go() {
    startdate1=j.From_date__c;
    enddate1=j.To_date__c;
    
    jb=[select Name,id,Experience__c,Required_skills__c,Salary__c,From_date__c,To_date__c from job__c where (From_date__c>=:startdate1) AND (To_date__c<=:enddate1)];
    
        return null;
    }
}

Hope this helps you!
Best Regards,
BNB
Balaji B 10Balaji B 10
for above code
This was selected as the best answer