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
krishnagkrishnag 

query to fetch records more than 10000

hi,

 

I have query like select count() some condition and it returns more than 10000 records.

 

As per the governor limits we cannot fetch more than 10000 records using query .What is the alternative to get rid of this limit.

EIE50EIE50

Hi,

 

You could use batch apex, and it is the only way by which you can query some millions of records without hitting the governor limits. You can find the document for writing batch apex here.

 

Thanks.

Pradeep_NavatarPradeep_Navatar

you can fetch the records in batches in 200 (the implicit query more pattern).

 

Try out the following sample code :

 

            for (List<Account> accts : [Select id from  account])

                                    {

                                                                  //The accts list will have 200 records at a time

                                                                 for (Account a : accts)

                                                                {

                                                                …

                                                                }

                                    }

 

Did this answer your question? if so, please mark it solved.

bob_buzzardbob_buzzard

I don't think that SOQL for loops allow you to workaround the governor limit of 10000 records.  It reduces the heap requirements as you process records in smaller batches, but the maximum number of records retrieved doesn't change.

krishnagkrishnag

yaa u r right Bob the above process doesnot give any solution but i thank you guys for your suggestions.But I am giving clear idea of my problem here.with the query.

 

i wrote a query for custom reporting purpose in which it should
give number of contacts in the org in the current year.

I gave the query as

select count() from Contact;

Its giving an exception too many query rows 10001. I have almost 12000
records of contacts how can i get the count of them using query is
there any alternative to get rid of governor limit.

amitashtekaramitashtekar

i am facing same issue. Could any one help me out.