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
pranavshahpranavshah 

Search Functionality in StandardSetController






\



System.SearchException: search term must be longer than one character:
Error is in expression '{!search_now}' in component <apex:commandButton> in page testvf4: Class.TestVF4.search_now: line 27, column 1
Class.TestVF4.search_now: line 27, column

I am getting above error in Vf page..
when i am trying to click on search button without entering any text


public class TestVF4 
{
    public List<Account> lstAccount {get;set;}
    private ApexPages.StandardSetController stndSetCtrl;
    public Integer pageNumber {get;set;}
    public Boolean isHasPrev {get;set;}
    public Boolean isHasNext {get;set;}
    public string  keyword {get; set;}

    public TestVF4()
    {
        lstAccount = new List<Account>();
        stndSetCtrl = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Name, Rating, Type, Industry from Account ORDER BY CreatedDate DESC]));//100
        stndSetCtrl.setPageSize(10);
        fetchRecords();
    }
    public string getkeyword()
    {
     return keyword;
    }    
    public void setkeyword(String input)
    {
     keyword=input;
    }
    public pageReference search_now()
    {
     lstAccount=(List<Account>)[FIND :keyword in all Fields Returning Account(Name, Rating, Type, Industry)][0];
     return null;
    }
    
    public void fetchRecords()
    {
        lstAccount = stndSetCtrl.getRecords();// 1-10
        pageNumber = stndSetCtrl.getPageNumber();
        isHasPrev = stndSetCtrl.getHasPrevious();
        isHasNext = stndSetCtrl.getHasNext();
    }
    public void next()
    {
        stndSetCtrl.next();
        fetchRecords();
    }
    public void prev()
    {
        stndSetCtrl.previous();
        fetchRecords();
    }
    public void first()
    {
        stndSetCtrl.first();
        fetchRecords();
    }
    public void last()
    {
        stndSetCtrl.last();
        fetchRecords();
    }
}
SandhyaSandhya (Salesforce Developers) 
Hi,

I would suggest you refer below links which has the sample code with explaination.

http://salesforcecode.blogspot.sg/2013/08/custom-dynamic-search-table-with.html
 
http://writeforce.blogspot.sg/2012/10/improving-our-search-functionality-by.html
 
Best Regards,
Sandhya