You need to sign in to do that
Don't have an account?
SeanCeno
Dynamic Search - OnKeyUp / SOQL escapeSingleQuotes
All,
I'm working on a project for a dynamic search of clients using Jeff Douglas's blog as a template
http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/
I have everything displayed correctly, but when I go to search, the debug soql query doesn't seem to be adding the search letter I type with the wild card. If you look at the demo here:
https://jeffdouglas-developer-edition.na5.force.com/examples/CustomerSearch
you can see that when a letter is entered, the debug soql changed to add that new search to the original soql.
From:
select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null order by lastName asc limit 20
To:
select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null and firstname LIKE 'a%' order by lastName asc limit 20
Does anybody have any idea why my search doesn't seem to be firing when the 'OnKeyUp' function is executed? I feel like it may have something to do with the 'escapeSingeQuotes' method or the LIKE.
Here is a snippet of my code:
I'm working on a project for a dynamic search of clients using Jeff Douglas's blog as a template
http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/
I have everything displayed correctly, but when I go to search, the debug soql query doesn't seem to be adding the search letter I type with the wild card. If you look at the demo here:
https://jeffdouglas-developer-edition.na5.force.com/examples/CustomerSearch
you can see that when a letter is entered, the debug soql changed to add that new search to the original soql.
From:
select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null order by lastName asc limit 20
To:
select firstname, lastname, account.name, interested_technologies__c from contact where account.name != null and firstname LIKE 'a%' order by lastName asc limit 20
Does anybody have any idea why my search doesn't seem to be firing when the 'OnKeyUp' function is executed? I feel like it may have something to do with the 'escapeSingeQuotes' method or the LIKE.
Here is a snippet of my code:
// runs the search with parameters passed via Javascript public PageReference runSearch() { String FirstName = Apexpages.currentPage().getParameters().get('FirstName'); String LastName = Apexpages.currentPage().getParameters().get('LastName'); String Broker = Apexpages.currentPage().getParameters().get('Broker_Dealer_Name__c'); String MailingCity = Apexpages.currentPage().getParameters().get('MailingCity'); String MailingState = Apexpages.currentPage().getParameters().get('MailingState'); String MailingPostalCode = Apexpages.currentPage().getParameters().get('MailingPostalCode'); String OwnerName = Apexpages.currentPage().getParameters().get('Owner.Name'); String NSIncomeProducerStatus = Apexpages.currentPage().getParameters().get('Producer_Status__c'); String NSIncomeIIProducerStatus = Apexpages.currentPage().getParameters().get('NS_Income_II_Producer_Status__c'); String NSIncomeHIProducerStatus = Apexpages.currentPage().getParameters().get('NS_HI_Producer_Status__c'); soql = 'select FirstName, LastName, Broker_Dealer_Name__c, MailingStreet, MailingCity, MailingState, MailingPostalCode, Owner.Name, Phone, Total_Sales__c, Producer_Status__c, NS_Income_II_Producer_Status__c, NS_HI_Producer_Status__c FROM Contact Where Broker_Dealer_Name__c !=null'; if (!FirstName.equals('')) soql += ' and FirstName LIKE \''+String.escapeSingleQuotes(FirstName)+'%\''; if (!LastName.equals('')) soql += ' and LastName LIKE \''+String.escapeSingleQuotes(LastName)+'%\''; if (!Broker.equals('')) soql += ' and Broker_Dealer_Name__c LIKE \''+String.escapeSingleQuotes(Broker)+'%\''; if (!MailingCity.equals('')) soql += ' and MailingCity LIKE \''+String.escapeSingleQuotes(MailingCity)+'%\''; if (!MailingState.equals('')) soql += ' and MailingState LIKE \''+String.escapeSingleQuotes(MailingState)+'%\''; if (!MailingPostalCode.equals('')) soql += ' and MailingPostalCode LIKE \''+String.escapeSingleQuotes(MailingPostalCode)+'%\''; if (!OwnerName.equals('')) soql += ' and Owner.Name LIKE \''+String.escapeSingleQuotes(OwnerName)+'%\''; if (!NSIncomeProducerStatus.equals('')) soql += ' and Producer_Status__c = (\''+NSIncomeProducerStatus+'\')'; if (!NSIncomeIIProducerStatus.equals('')) soql += ' and NS_Income_II_Contact_Type__c = (\''+NSIncomeIIProducerStatus+'\')'; if (!NSIncomeHIProducerStatus.equals('')) soql += ' and NS_HI_Contact_Type__c = (\''+NSIncomeHIProducerStatus+'\')'; // run the query again runQuery(); return null; }
All Answers