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
onedayoneday 

what does 'limit' keyword do in a query

If I use the 'limit' keyword in the query string as "Select Id from Account where Name='test' limit 1", will the query operation return immediately once it found a matched Account?

 

I am asking this because I would like to know if the query could be more efficient if I used the 'limit' keyword.

Message Edited by oneday on 01-29-2009 08:37 AM
Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell
It will stop the query when the number of rows found matches the limit clause.

All Answers

dev_jhdev_jh

Take a look at the docs:

 

http://www.salesforce.com/us/developer/docs/api90/Content/sforce_api_calls_soql_select.htm#i1422156

 

They don´t necesarily explain how it works in technical terms (ie: does it grab all records but only returns the first one?) but if you want to limit the number of rows returned in SOQL this seems the optimal way to do it.

 

J

onedayoneday
Thanks for the reply, but I asked this question because I would like to know if using 'limit' could make the query more efficient.
SuperfellSuperfell
yes it will
onedayoneday
It will return the matched sObjects immediately?
SuperfellSuperfell
It will stop the query when the number of rows found matches the limit clause.
This was selected as the best answer