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
salesforce1#salesforce1# 

How can bypass SOQL statement to fetch more 1000 records in salesforce

Hi

 

How can bypass SOQL statement to fetch more 1000 records in salesforce

Best Answer chosen by Admin (Salesforce Developers) 
Shailesh DeshpandeShailesh Deshpande
HI Balakrishna,

As vinit said that the limit has been revised to 50,000. But this limit is for entire transaction. This means you can have for eg. 10 queries returning 5000 records. Or you can have 1 query returning 50000 records. Once you reach 50,000 records you cannot issue any more queries for that transaction.

Although the limit has been enhanced to 50,000 I have received an error several times when the query returns more than 1000 records. In such cases:

You can use a FOR SOQL to overcome this limit.

So if your regular query is as below:

List<Account> accounts = new List<Account>();
accounts = [Select Id, Name from Account];

then instead of the above query you can use:

List<Account> accounts = new List<Account>();

for(Account acc : [Select Id, Name from Account])
{
accounts.add(acc);
}

However do note that this can work upto 50,000 records.

All Answers

sfdcfoxsfdcfox

The limit of 1000 no longer applies (except in some special circumstances). Could you elaborate on your problem?

salesforce1#salesforce1#
Hi sfdcfox,

this is the interview question one of my friend asking.
can you explain how can you bypass the SOQL statements.
is there any document for that.

Vinit_KumarVinit_Kumar

The current limit is 50000 records which can be fetched through SOQL,not sure from where you got 1000 records.Please go through the below link for the same:-

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

Shailesh DeshpandeShailesh Deshpande
HI Balakrishna,

As vinit said that the limit has been revised to 50,000. But this limit is for entire transaction. This means you can have for eg. 10 queries returning 5000 records. Or you can have 1 query returning 50000 records. Once you reach 50,000 records you cannot issue any more queries for that transaction.

Although the limit has been enhanced to 50,000 I have received an error several times when the query returns more than 1000 records. In such cases:

You can use a FOR SOQL to overcome this limit.

So if your regular query is as below:

List<Account> accounts = new List<Account>();
accounts = [Select Id, Name from Account];

then instead of the above query you can use:

List<Account> accounts = new List<Account>();

for(Account acc : [Select Id, Name from Account])
{
accounts.add(acc);
}

However do note that this can work upto 50,000 records.
This was selected as the best answer
salesforce1#salesforce1#

Hi shailesh,

 

thank you very much for your guidence.