<apex:page controller="AccountList" tabStyle="Account"> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel for="searchText">Search By Name</apex:outputLabel> <apex:inputText id="searchByName" value="{!searchByName}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection>
<apex:page controller="AccountList" tabStyle="Account">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchText">Search By Name</apex:outputLabel>
<apex:inputText id="searchByName" value="{!searchByName}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchText">Search By Rating</apex:outputLabel>
<apex:selectRadio value="{!searchByRating}">
<apex:selectOption itemLabel="Cold" itemValue="Cold"></apex:selectOption>
<apex:selectOption itemLabel="Hot" itemValue="Hot"></apex:selectOption>
<apex:selectOption itemLabel="Warm" itemValue="Warm"></apex:selectOption>
</apex:selectRadio>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<!-- Implement Web Service -->
<apex:outputLabel for="searchText">Search By State</apex:outputLabel>
<apex:selectList size="1" value="{!searchByState}">
<apex:selectOption itemLabel="" itemValue=""></apex:selectOption>
<apex:selectOption itemLabel="KS" itemValue="KS"></apex:selectOption>
<apex:selectOption itemLabel="CA" itemValue="CA"></apex:selectOption>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<!-- Implement Web Service -->
<apex:outputLabel for="searchText">Logical Operator</apex:outputLabel>
<apex:selectList size="1" value="{!searchCriteria}">
<apex:selectOption itemLabel="AND" itemValue="AND"></apex:selectOption>
<apex:selectOption itemLabel="OR" itemValue="OR"></apex:selectOption>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchText">Search </apex:outputLabel>
<apex:commandButton value="Go1!" action="{!doSearch}" reRender="theBlock"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockSection title="Results" columns="1">
<apex:actionRegion >
<apex:pageBlockTable value="{!accounts}" var="account" id="theBlock">
<apex:column headerValue="Action">
<apex:outputLink value="{!URLFOR($Action.Account.Edit, account.Id)}">Edit (Action)</apex:outputLink> -
<apex:outputLink value="/{!account.Id}/e?">Edit (URL)</apex:outputLink>
</apex:column>
<apex:column value="{!account.Name}" />
<apex:column value="{!account.Rating}" />
<apex:column value="{!account.BillingState}" />
</apex:pageBlockTable>
</apex:actionRegion>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
</apex:page>
public class AccountList {
String searchTerms = '';
public String showGo { get; set; }
public String searchCriteria { get; set; }
public String searchByState { get; set; }
public String searchByRating { get; set; }
public String searchByName { get; set; }
public List<Account> accounts {
get;
private set;
}
public PageReference doSearch() {
searchTerms = 'select Name, Rating, BillingState from Account where';
if (!String.isEmpty(searchByName))
searchTerms += ' Name LIKE \''+String.escapeSingleQuotes(searchByName)+'%\'';
if (!String.isEmpty(searchByRating)){
if (!String.isEmpty(searchByName)){
searchTerms += ' '+searchCriteria+' Rating LIKE \''+String.escapeSingleQuotes(searchByRating)+'%\'';
//searchTerms += ' or Rating LIKE \''+String.escapeSingleQuotes(searchByRating)+'%\'';
} else {
searchTerms += ' Rating LIKE \''+String.escapeSingleQuotes(searchByRating)+'%\'';
}
}
if (!String.isEmpty(searchByState)){
if (!String.isEmpty(searchByName) || !String.isEmpty(searchByRating)){
searchTerms += ' '+searchCriteria+' BillingState LIKE \''+String.escapeSingleQuotes(searchByState)+'%\'';
//searchTerms += ' or BillingState LIKE \''+String.escapeSingleQuotes(searchByState)+'%\'';
} else {
searchTerms += ' BillingState LIKE \''+String.escapeSingleQuotes(searchByState)+'%\'';
}
}
if(!String.isEmpty(searchTerms)){
//results = (List<Account>)[FIND :searchTerms RETURNING Account(Name, Rating, BillingState)][0];
System.debug('searchTerms -'+searchTerms);
accounts = Database.query(searchTerms);
}
return null;
}
/*public AccountList() {
accounts = [select name, rating, billingstate from account];
}*/
}
}