Search Engine using Apex and Visualforce

Visualforce:

<apex:page standardController="Member__c" extensions="Search" >

  <style type = "text/css">

    .Bld { font-weight:bold;}
  </style>
 
  <apex:form >
 
    <apex:pageblock title="Members" >
      <table align = "center" width = "100%" cellspacing = "5">
        <tr>
          <td class = "Bld">Member Name:</td>
          <td><apex:inputText value="{!memName}" /></td>         
        </tr>
        <tr>
          <td align = "center" class = "Bld" colspan = "2"><apex:commandButton value="Find" action="{!find}"/></td>
        </tr>       
      </table>
      
    </apex:pageblock>
       
    <apex:pageBlock title="Search Result">
      <apex:pageblockTable value="{!memList}" var="a">
        <apex:column >
          <apex:outputlink value="https://na12.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
        </apex:column>
        <apex:column value="{!a.id}"/>
      </apex:pageBlockTable>    
    </apex:pageBlock>   
     
  </apex:form>
</apex:page>


Apex:

public class Search
{
 
  public String memName {get; set;}
 
  public List<Member__c>  memList {get; set;}
 
  public Search(ApexPages.StandardController controller)
  {
  }
 
  public void find()
  {
    String sql = 'SELECT Name,id FROM Member__c WHERE Name LIKE \'%'+memName+'%\' LIMIT 20';
    memList = Database.query(sql);
  } 
}

No comments:

Post a Comment