+ Start a Discussion
sales@myvarmasales@myvarma 

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;

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







<apex:page controller="OppNameSearchController" >
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockSection title="Search Filter" >
                Opportunity Name: <apex:inputText value="{!searchstring}"/>
                <apex:commandButton value="Search" action="{!method}" />
            </apex:pageBlockSection>
            <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:inlineEditSupport>
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!clear}" value="reset"/>
            </apex:pageBlockSection>
        </apex:pageBlock>        
           
        
    </apex:form>
</apex:page>



 
Saravana Bharathi 1Saravana Bharathi 1
Hi,

That is Salesforce SOSL Limitations. Refer this link.

https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/reference_objects_sosl_limits.htm

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

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

Thanks
Alex EzhilarasanAlex Ezhilarasan

Hi Pradeep Varma,

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

Thanks,
Alex