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
risharisha 

i have doubt in soql query

why we used Limit 1 in query?can any one help me coz i'm new to salesforce

Best Answer chosen by Admin (Salesforce Developers) 
@anilbathula@@anilbathula@

Hi risha,

Limit is used to limit the records in soql query.
If you have 300 records in ur contact object .if you query on contact object with the following query:
Contact c=[select id,name form contact];
system.debug('---->'+c);
The query will return all 300 records.
if you put limit in query it will return only one record in the query
ex:-
Contact c=[select id,name form contact limit 1];
system.debug('---->'+c);
If you have more than 50000 records to query use list.

All Answers

@anilbathula@@anilbathula@

Hi risha,

Limit is used to limit the records in soql query.
If you have 300 records in ur contact object .if you query on contact object with the following query:
Contact c=[select id,name form contact];
system.debug('---->'+c);
The query will return all 300 records.
if you put limit in query it will return only one record in the query
ex:-
Contact c=[select id,name form contact limit 1];
system.debug('---->'+c);
If you have more than 50000 records to query use list.

This was selected as the best answer
Deepak Kumar ShyoranDeepak Kumar Shyoran

Hi risha,

 

You are using Limit 1 in your code to limit the records returned by your SOQL query to maximum 1 record.

 

You can change this limit according to your need and can limit to Max 50000 i.e. Limit 50000 in your SOQL to retrieve maximum 50000 records.

 

Ex :-

 List<Account> accLst = [Select id,Name from Account Limit 100] ;

 the above query will return Max 100 records.

 

If this post helps you then hit kudus by clicking on star and accept my post as a solution to your question.

 

risharisha

thanks a lot for helped me now i understood clearly