Search Pages


Example 1: Search in Lead 
  1. <apex:page controller="ourLeadController" >
  2. <apex:form >
  3. <apex:pageblock >
  4.     <apex:inputtext value="{!searchText}"/>
  5.     <apex:commandButton value="Perform Search" action="{!doSearch}" rerender="block"/>
  6. </apex:pageblock>
  7. <apex:pageblock id="block">
  8.     <apex:pageblocktable value="{!results}" var="l">
  9.         <apex:column value="{!l.name}"/>
  10.         <apex:column value="{!l.phone}"/>
  11.         <apex:column value="{!l.email}"/>
  12.     </apex:pageblocktable>
  13. </apex:pageblock>
  14. </apex:form>
  15. </apex:page>
  1. public with sharing class ourLeadController {
  2. String thetext;
  3. list<lead> results;

  4. public List<lead> getResults(){
  5.     return results;
  6. public pageReference doSearch(){
  7.     results = (list<lead>)[find: thetext returning lead(name, phone, email)][0];
  8.     return null;
  9. }
  10. public string getsearchtext(){
  11.     return null;
  12. }
  13. public void setsearchtext(string s){
  14.     thetext=s;
  15. }

  16. }







Example 2: snippet 

List<List<SObject>> searchList= [FIND 'map*' IN NAME FIELDS RETURNING Account (id, name),Contact];
Account [ ] accounts= ((List<Account>)searchList[0]);

Contact [ ] contacts= ((List<Contact>)searchList[1]);

Comments

Popular posts