Wild Card Searching SOQL in Salesforce

Requirement: Data Filter Based on any Character 


Page Code

<apex:page controller="wildcardController">
  <apex:form >
    <apex:pageblock >
        
        <apex:inputtext value="{!inputtext}"/>
        <apex:commandbutton value="Search" action="{!searchRecords}" reRender="ss,msgid"/>
    </apex:pageblock>
    <apex:pageblock id="pbId">
      <apex:pageblocktable value="{!accList}" var="acc" id="ss">
        <apex:column value="{!acc.name}"/>
        <apex:column value="{!acc.accountnumber}"/>
      </apex:pageblocktable>
    </apex:pageblock>
    <apex:outputLabel value="{!str}" id="msgid"></apex:outputLabel>
  </apex:form>

</apex:page>

Class Code

Public class wildcardController {
    Public string inputtext{get;set;}
    Public List<account> accList{get;set;}
    public string str{get;set;}
    //Public boolean flagshow{get;set;}
    Public wildcardController(){
     //flagshow = false;
    }    
    Public void searchRecords(){
    // flagshow = true;
      accList = database.Query('select name,accountnumber from account where name like '+'\''+'%'+inputtext+'%'+'\'');
      system.debug('******'+accList.size());

      
    if(accList .size() ==0)
    {
        str= 'No Data Found based on the Search Criteria.';
    }
    else
    {
        str= '';
    }
    }
  

}

Snapshot



Thanks
Sumit Shukla



Comments

Popular posts from this blog

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page