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
foneminefonemine 

QUERY_TIMEOUT error

I am doing simple query thru salesforce soap webservice(even tried with rest service) "SELECT Id, Name FROM Lead order by Name limit 50". For this query I am getting the following error "QUERY_TIMEOUT: Your query request was running for too long". For the same query, I sometime get result in 2 seconds.

If I change the abouve query to "select Id, Name from Lead Order by Id limit 50", it always reponsds by 2 seconds. Is there some kind of index that has to done for "Name" column. 

Note: The Lead table contains about "983940" rows. 

Can anyone help me in solving this issue. 
HawkedHawked
If you are wondering why the speed difference : 

This is due to an optimization introduced at the Database level that takes advantage of the fact that IDs are ordered. 
Ref: https://help.salesforce.com/apex/HTViewSolution?id=000171421&language=en_US


How to solve this :

Try adding IsDeleted = FALSE to your query and see how the results work for you. 

https://help.salesforce.com/apex/HTViewSolution?id=000007178&language=en_US
 
foneminefonemine
I tied with adding isDeleted = FALSE, but same issue. 

"SELECT Id, Name FROM Lead  where isDeleted = FALSE order by Name limit 50".

Also, I believe "Name" is the standard field and its ordered(is my assuption correct?), and I am not sure why the query is timing out.