You need to sign in to do that
Don't have an account?
Hemant_Soni
Alphabat search
Hi.....
i am trying to do searching with header alphabat but it is not gives right output so please help me.....
and i am very confuse about the quey because i am use 26 query for alphbat search..
HERE IS MY CONTROLLER
public class searchcontroller {
String sortDirection = 'ASC';
String sortExp = 'name';
string searchaccount;
list < account > lst;
public string getsearchtext() {
return searchaccount;
}
public void setsearchtext(string s) {
searchaccount = s;
}
public string getsearchtext1() {
return searchaccount;
}
public void setsearchtext1(string s1) {
searchaccount = s1;
}
public list < account > getlst() {
return lst;
}
public PageReference doSearch() {
if (searchaccount =='' && searchaccount != null) {
lst = [SELECT id, name, phone, billingcity from Account ORDER by name limit 27];
} else {
if (searchaccount == 'A') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'A%'limit 5];
} else
if (searchaccount == 'B') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'B%'limit 5];
} else
if (searchaccount == 'C') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'C%'limit 5];
} else
if (searchaccount == 'D') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'D%'limit 5];
} else
if (searchaccount == 'E') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'E%'limit 5];
} else
if (searchaccount == 'F') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'F%'limit 5];
} else
if (searchaccount == 'G') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'G%'limit 5];
} else
if (searchaccount == 'H') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'H%'limit 5];
} else
if (searchaccount == 'I') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'I%'limit 5];
} else
if (searchaccount == 'J') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'J%'limit 5];
} else
if (searchaccount == 'K') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'K%'limit 5];
} else
if (searchaccount == 'L') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'L%'limit 5];
} else
if (searchaccount == 'M') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'M%'limit 5];
} else
if (searchaccount == 'N') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'N%'limit 5];
} else
if (searchaccount == 'O') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'O%'limit 5];
} else
if (searchaccount == 'P') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'P%'limit 5];
} else
if (searchaccount == 'Q') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'Q%'limit 5];
} else
if (searchaccount == 'R') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'R%'limit 5];
} else
if (searchaccount == 'S') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'S%'limit 5];
} else
if (searchaccount == 'T') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'T%'limit 5];
} else
if (searchaccount == 'U') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'U%'limit 5];
} else
if (searchaccount == 'V') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'V%'limit 5];
} else
if (searchaccount == 'W') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'W%'limit 5];
} else
if (searchaccount == 'X') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'X%'limit 5];
} else
if (searchaccount == 'Y') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'Y%'limit 5];
} else
if (searchaccount == 'Z') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'Z%'limit 5];
} else
if (searchaccount == 'All') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like '%'limit 5];
}
}
return null;
}
public PageReference next() {
return doSearch();
}
public PageReference previous() {
return doSearch();
}
public String sortExpression {
get {
return sortExp;
}
set {
if (value == sortExp)
sortDirection = (sortDirection == 'ASC') ? 'DESC' : 'ASC';
else
sortDirection = 'ASC';
sortExp = value;
}
}
public String getSortDirection() {
if (sortExpression == null || sortExpression == '')
return 'ASC';
else
return sortDirection;
}
public void setSortDirection(String value) {
sortDirection = value;
}
public PageReference ViewData() {
string sortFullExp = sortExpression + ' ' + sortDirection;
lst = Database.query('Select id, Name, BillingCity, BillingCountry, Phone from Account order by ' + sortFullExp + ' limit 27');
return null;
}
}
and This is my VF page
<apex:page controller="searchcontroller">
<apex:form >
<script type='text/javascript'>
function runOnEnter(ev) {
if (window.event && window.event.keyCode == 13 || ev.which == 13) {
searchAccRecs();
return false;
} else {
return true;
}
}
</script>
<apex:pageBlock title="Search Account" id="block">
<span style="position:initial; top:145px; left:840px;">
<apex:commandLink value="A |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="B |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="C |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="D |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="E |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="F |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="G |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="H |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="I |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="J |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="K |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="L |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="M |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="N |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="O |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="P |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="Q |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="R |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="S |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="T |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="U |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="V |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="W |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="X |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="Y |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="Z |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="Other |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="All" action="{!doSearch}" reRender="block"/>
</span>
<apex:pageBlockSection title="Account">
<apex:outputLabel for="searchaccount" rendered="false">Search Text</apex:outputLabel>
<apex:inputText id="searchaccount" value="{!searchText}" onkeypress="return runOnEnter(event);" />
<apex:commandButton value="search" style="position:initial; top:195px; left:450px;" onkeypress="return" action="{!doSearch}" status="searchStaus" reRender="block" id="thesearch" />
<apex:actionstatus id="searchStaus">
<apex:facet name="start">
<span style="color:red;font-weight:bold; position:fixed; top:220px; left:500px;">searching...</span>
<img src="/img/loading.gif" alt="" style="position:fixed; top:220px; left:600px;" />
</apex:facet>
</apex:actionstatus>
</apex:pageBlockSection>
<apex:pageBlockSection title="Detail View" id="lst" rendered="{!NOT(ISNULL(lst))}">
<apex:pageBlockTable value="{!lst}" var="l" rendered="{!NOT(ISNULL(lst))}" style="width:242%;">
<apex:column value="{!l.Id}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Account id{!IF(sortExpression=='id',IF(sortDirection='ASC','▼','▲'),'')}" reRender="block">
<apex:param value="id" name="column" assignTo="{!sortExpression}"></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!l.Phone}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Phone{!IF(sortExpression=='Phone',IF(sortDirection='ASC','▼','▲'),'')}" reRender="block">
<apex:param value="Phone" name="column" assignTo="{!sortExpression}"></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!l.BillingCity}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Billing City{!IF(sortExpression=='BillingCity',IF(sortDirection='ASC','▼','▲'),'')}" reRender="block">
<apex:param value="BillingCity" name="column" assignTo="{!sortExpression}"></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!l.Name }">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='Name',IF(sortDirection='ASC','▼','▲'),'')}" reRender="block">
<apex:param value="Name" name="column" assignTo="{!sortExpression}"></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:actionFunction name="searchAccRecs" action="{!doSearch}" reRender="block" />
</apex:form>
</apex:page>
i am trying to do searching with header alphabat but it is not gives right output so please help me.....
and i am very confuse about the quey because i am use 26 query for alphbat search..
HERE IS MY CONTROLLER
public class searchcontroller {
String sortDirection = 'ASC';
String sortExp = 'name';
string searchaccount;
list < account > lst;
public string getsearchtext() {
return searchaccount;
}
public void setsearchtext(string s) {
searchaccount = s;
}
public string getsearchtext1() {
return searchaccount;
}
public void setsearchtext1(string s1) {
searchaccount = s1;
}
public list < account > getlst() {
return lst;
}
public PageReference doSearch() {
if (searchaccount =='' && searchaccount != null) {
lst = [SELECT id, name, phone, billingcity from Account ORDER by name limit 27];
} else {
if (searchaccount == 'A') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'A%'limit 5];
} else
if (searchaccount == 'B') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'B%'limit 5];
} else
if (searchaccount == 'C') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'C%'limit 5];
} else
if (searchaccount == 'D') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'D%'limit 5];
} else
if (searchaccount == 'E') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'E%'limit 5];
} else
if (searchaccount == 'F') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'F%'limit 5];
} else
if (searchaccount == 'G') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'G%'limit 5];
} else
if (searchaccount == 'H') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'H%'limit 5];
} else
if (searchaccount == 'I') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'I%'limit 5];
} else
if (searchaccount == 'J') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'J%'limit 5];
} else
if (searchaccount == 'K') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'K%'limit 5];
} else
if (searchaccount == 'L') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'L%'limit 5];
} else
if (searchaccount == 'M') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'M%'limit 5];
} else
if (searchaccount == 'N') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'N%'limit 5];
} else
if (searchaccount == 'O') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'O%'limit 5];
} else
if (searchaccount == 'P') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'P%'limit 5];
} else
if (searchaccount == 'Q') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'Q%'limit 5];
} else
if (searchaccount == 'R') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'R%'limit 5];
} else
if (searchaccount == 'S') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'S%'limit 5];
} else
if (searchaccount == 'T') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'T%'limit 5];
} else
if (searchaccount == 'U') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'U%'limit 5];
} else
if (searchaccount == 'V') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'V%'limit 5];
} else
if (searchaccount == 'W') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'W%'limit 5];
} else
if (searchaccount == 'X') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'X%'limit 5];
} else
if (searchaccount == 'Y') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'Y%'limit 5];
} else
if (searchaccount == 'Z') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like 'Z%'limit 5];
} else
if (searchaccount == 'All') {
lst = [SELECT id, Name, phone, billingcity FROM Account where name like '%'limit 5];
}
}
return null;
}
public PageReference next() {
return doSearch();
}
public PageReference previous() {
return doSearch();
}
public String sortExpression {
get {
return sortExp;
}
set {
if (value == sortExp)
sortDirection = (sortDirection == 'ASC') ? 'DESC' : 'ASC';
else
sortDirection = 'ASC';
sortExp = value;
}
}
public String getSortDirection() {
if (sortExpression == null || sortExpression == '')
return 'ASC';
else
return sortDirection;
}
public void setSortDirection(String value) {
sortDirection = value;
}
public PageReference ViewData() {
string sortFullExp = sortExpression + ' ' + sortDirection;
lst = Database.query('Select id, Name, BillingCity, BillingCountry, Phone from Account order by ' + sortFullExp + ' limit 27');
return null;
}
}
and This is my VF page
<apex:page controller="searchcontroller">
<apex:form >
<script type='text/javascript'>
function runOnEnter(ev) {
if (window.event && window.event.keyCode == 13 || ev.which == 13) {
searchAccRecs();
return false;
} else {
return true;
}
}
</script>
<apex:pageBlock title="Search Account" id="block">
<span style="position:initial; top:145px; left:840px;">
<apex:commandLink value="A |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="B |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="C |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="D |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="E |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="F |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="G |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="H |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="I |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="J |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="K |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="L |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="M |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="N |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="O |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="P |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="Q |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="R |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="S |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="T |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="U |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="V |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="W |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="X |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="Y |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="Z |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="Other |" action="{!doSearch}" reRender="block"/>
<apex:commandLink value="All" action="{!doSearch}" reRender="block"/>
</span>
<apex:pageBlockSection title="Account">
<apex:outputLabel for="searchaccount" rendered="false">Search Text</apex:outputLabel>
<apex:inputText id="searchaccount" value="{!searchText}" onkeypress="return runOnEnter(event);" />
<apex:commandButton value="search" style="position:initial; top:195px; left:450px;" onkeypress="return" action="{!doSearch}" status="searchStaus" reRender="block" id="thesearch" />
<apex:actionstatus id="searchStaus">
<apex:facet name="start">
<span style="color:red;font-weight:bold; position:fixed; top:220px; left:500px;">searching...</span>
<img src="/img/loading.gif" alt="" style="position:fixed; top:220px; left:600px;" />
</apex:facet>
</apex:actionstatus>
</apex:pageBlockSection>
<apex:pageBlockSection title="Detail View" id="lst" rendered="{!NOT(ISNULL(lst))}">
<apex:pageBlockTable value="{!lst}" var="l" rendered="{!NOT(ISNULL(lst))}" style="width:242%;">
<apex:column value="{!l.Id}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Account id{!IF(sortExpression=='id',IF(sortDirection='ASC','▼','▲'),'')}" reRender="block">
<apex:param value="id" name="column" assignTo="{!sortExpression}"></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!l.Phone}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Phone{!IF(sortExpression=='Phone',IF(sortDirection='ASC','▼','▲'),'')}" reRender="block">
<apex:param value="Phone" name="column" assignTo="{!sortExpression}"></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!l.BillingCity}">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Billing City{!IF(sortExpression=='BillingCity',IF(sortDirection='ASC','▼','▲'),'')}" reRender="block">
<apex:param value="BillingCity" name="column" assignTo="{!sortExpression}"></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{!l.Name }">
<apex:facet name="header">
<apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='Name',IF(sortDirection='ASC','▼','▲'),'')}" reRender="block">
<apex:param value="Name" name="column" assignTo="{!sortExpression}"></apex:param>
</apex:commandLink>
</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:actionFunction name="searchAccRecs" action="{!doSearch}" reRender="block" />
</apex:form>
</apex:page>
pcon
No where on your Visualforce page are you actually setting the searchAccount variable that you are using for your queries. Additionally the following statement can never be true.