+ Start a Discussion

search option

i want to get results even if i give single letter in searchfield
help me in getting output i tried to manage but still errors 

public class OppNameSearchController {
    public string Name{set;get;}
    public Decimal amount{set;get;}
    public Opportunity Opp{set;get;}
    public string searchstring {get;set;} 
    public boolean show{set;get;}
    public void method()
       if(searchstring != null && searchstring != '' ){  
    string searchquery='select Name, Amount from opportunity where Name like \'%'+searchstring+'%\'  Limit 10';  
     Opp = Database.query(searchstring); 
           show = true;

            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'There are no Opportunities with the Name -'  +searchstring);
            show = false;
    public void save()
        Opportunity op = Opp;
        update op;
     public void clear(){  

<apex:page controller="OppNameSearchController" >
        <apex:pageBlock >
            <apex:pageBlockSection title="Search Filter" >
                Opportunity Name: <apex:inputText value="{!searchstring}"/>
                <apex:commandButton value="Search" action="{!method}" />
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockSection title="Searched Record" rendered="{!show}" >
                <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                                        hideOnEdit="editButton" event="ondblclick" 
                                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit">
                    <apex:outputField value="{!Opp.Name}"></apex:outputField>
                    <apex:outputField value="{!Opp.Amount}"/>
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!clear}" value="reset"/>

Saravana Bharathi 1Saravana Bharathi 1

That is Salesforce SOSL Limitations. Refer this link.


Even, in Salesforce Global Search wont work for single letter search.

Instead, throw error message to enter atleast 2 character, before doing search operation.

Alex EzhilarasanAlex Ezhilarasan

Hi Pradeep Varma,

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