Can anyone help me figure out what's wrong in the code, the search button only worked once and second time onwards it's not working?
Apex Code
public void showAccounts(){
system.debug('Entethere=====');
string strQuery = 'select id,name,(select id,Email from contacts where Receives_Maintenance_Notifications__c=true) from account ORDER BY Name ASC';
//strSearchBy = 'Name';
if(strSearchBy!=null && strSearchBy!=''){
strQuery = strQuery+ ' where '+strSearchBy+ '=\''+strSearchText+'\'';
strQuery = strQuery+ ' where '+strSearchBy+ '=\''+strSearchText+'\'';
}
system.debug('strQuery===='+strQuery);
list<Account> lstAccount =DataBase.Query(strQuery);
lstWrapper.clear();
for(account objAccount :lstAccount){
system.debug('objAcc====='+objAccount);
if(objAccount.contacts.size()!=0){
AccountWrapper objWrapper = new AccountWrapper();
objWrapper.AccountRecord = objAccount;
objWrapper.numberOfContacts = objAccount.contacts.size();
lstWrapper.add(objWrapper);
}
}
Visualforce
<apex:inputText value="{!strSearchText}"/>
<apex:commandButton value="Search" action="{!showAccounts}"/>
<apex:pageBlockTable value="{!lstWrapper}" var="vrAccount">
<apex:column headerValue="Account">
<apex:inputcheckbox value="{!vrAccount.bSelectedrecord}"/>
</apex:column>
<apex:column value="{!vrAccount.AccountRecord.name}"/>
<apex:column value="{!vrAccount.numberOfContacts}" headerValue="Number of Contacts"/>
</apex:pageBlockTable>
unexpected token: where
Error is in expression
'{!showAccounts}'
in component<apex:commandButton>
in pageemailtool: Class.EmailToolController.showAccounts
: line 52, column 1An unexpected error has occurred. Your development organization has been notified.