Thursday, May 3, 2012

So I stumbled upon a use case where users were subjected to a search page on a Salesforce powered site. Users often complained how irrelevant search results were. When I looked at it , my first reaction was well Salesforce has taken great pains in providing a whole Search Specific functionality. Let's do it.So, I decided to use SOSL.

To my dismay , I came across so many restrictions , I am thinking I should go back to SOQL.

Here are the pitfalls I found :

1. Search groups are either too restrictive or too large. I cannot search on Text Area if I use NAME Fields and if I do ALL Fields I end up searching in rather unuseful text areas which only serve to return junk items in search result set.

2. I cannot control searchable fields via field security. So, smart alecs .. its of no use.

3. The fanciful functionality of being able to search through multiple objects isn't much useful in a scenario like below

 I have to show a list of all accounts that qualify the search criteria plus accounts with related contacts that qualify the search critetria as well.

Now, in order to get the list of Accounts for which contacts match as well , I have to fire a SOQL query anyways , so what's the point !

4. Wild card cannot be applied to the beginning of the search phrase.


Benefits :

1. At least it supports wild card characters.

I wanted to search through text areas for phrases. Text Area was set up like of a Related Tags kind of thing. Users would always add tags seperated by coma (' , ') symbol.

So, forming a criteria in this form worked for me :

wildCardCriteria =
'\''+criteria+'* OR ,'+criteria+'*\'';