Another Salesforce blog!!!

Salesforce, Apex

Ajax wild card search


<apex:page controller="AjaxWildcardController">
  <apex:form >
      <apex:pageBlock >
        Type Account Name Here :<apex:inputText value="{!inputtext}" >
          <apex:actionSupport action="{!actionSupMethod}" event="onkeyup" reRender="outptText" />
        </apex:inputtext>
      </apex:pageBlock>  

    <apex:pageblock >
      <apex:pageblocktable value="{!accList}" var="acc" id="outptText">
        <apex:column value="{!acc.name}"/>
        <apex:column value="{!acc.accountnumber}"/>
      </apex:pageblocktable>
    </apex:pageblock>
  </apex:form>
</apex:page>
public class AjaxWildcardController {

    public string inputtext{get;set;}
    public List<account> accList{get;set;}
    public boolean flagshow{get;set;}
    
    public AjaxWildcardController(){
        flagshow = false;
    }    
    
    Public void actionSupMethod(){  
      accList = database.Query('select name,accountnumber from account where name like '+'\''+'%'+inputtext+'%'+'\'');
    } 
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*