unexpected token: 'Where'
Error is in expression '{!Showaccounts1}' in page emailtoolpage: Class.EmailController.showAccounts1: line 141, column 1
An unexpected error has occurred. Your development organization has been notified.
The following is the class,
public void showAccounts1(){
system.debug('test');
if (AlphaFilter == null || AlphaFilter.trim().length() == 0) {
AlphaFilter = 'All';
}
string strQuery = 'select id,name,(select id,Email from contacts where Receives_Maintenance_Notifications__c=true) from account';
if (AlphaFilter != 'All') {
if(strQuery.indexOf('Where')!=-1){
strQuery = strQuery + ' and Name LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\'';
}
//QueryWhere = BuildWhere(QueryWhere, '(' + String.escapeSingleQuotes(SortField) + ' LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\')' );
else{
strQuery = strQuery + ' where Name LIKE \'' + String.escapeSingleQuotes(AlphaFilter) + '%\'';
}
}
system.debug('strQuery ====***'+strQuery);
//string strQuery = 'select id,name,(select id,Email from contacts where Receives_Maintenance_Notifications__c=true) from account';
strSearchBy='Name';
if(strSearchBy!=null && strSearchBy!='' && strSearchText!=null && strSearchText!=''){
if(strQuery.indexOf('Where')!=-1){
strQuery = strQuery + ' and Name LIKE \'' + String.escapeSingleQuotes(strSearchText) + '%\'';
}
else{
//strQuery = strQuery+ ' where '+strSearchBy+ '=\''+strSearchText+'\'';
strQuery = strQuery + ' Where Name LIKE \'' + String.escapeSingleQuotes(strSearchText) + '%\'';
}
}
system.debug('objToolFinal==='+strQuery);
list<Account> lstAccount =DataBase.Query(strQuery);
system.debug('lstAccount==='+lstAccount);
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);
}
3 respostas
