function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
prufrockprufrock 

First Time Search Delay

Hello,
 
Recently I developed an S-control where I had to retrieve Lead records. The search I have done is based on "phone" column. The query is: Select Id, City, FirstName, LastName, MobilePhone, Phone, PostalCode, State, Street from Lead where IsConverted = false and phone='(111) 111-1111'
 
The problem we have now is that the first time we invoke the S-control, the query is really slow. However the subsequent times with any phone number, including the one from example, the query returns significantly faster.
 
My question is have anybody in this board experienced this problem, and if you did do you know the remedy?
 
Many thanks for your kind attention.
 
werewolfwerewolf
The reason is that the first time the query is hitting the database.  The second time it's cached or in memory so it's faster.

May I strongly suggest that you do this with a SOSL search instead of a SOQL search, like FIND {4155551212} IN PHONE FIELDS RETURNING Lead(Id, City, FirstName, LastName, MobilePhone, Phone, PostalCode, State, Street) ?  It will be considerably faster.  You won't necessarily be able to filter out the IsConverted = false in the query, but you can easily do that when the query returns, just go through the returned leads and chuck any converted ones.
werewolfwerewolf
Don't forget you have to use the search() call instead of the query() call to do a SOSL search.