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
SuvraSuvra 

Handling more than 10,000 records

Hi,

 

I have one SOQL which will retrieve nearly 50k records. Can anyone please tell me how to handle this scenario.

As SOQL is able to retrieve at most 10,000 records, somehow I need to pass the start index to SOQL to retrieve set of next 10,000 recs..etc.

 

Is it possible at all? How will Batch apex help in this?

 

Thanks ain advance,

Suvra

Rajesh ShahRajesh Shah
Where are you using the query? Trigger, Apex Class or Visualforce Controller?
J&A-DevJ&A-Dev

With Batch Apex, your SOQL will be able to retrieve up to 50,000,000 records and process them. So you wouldn't have to worry about indexes at all. However, you're indeed limited to 10,000 recods/SOQL call if you have to use Visualforce or a regular Apex class/trigger.

 

If you haven't already done so, take a look at the docs: http://www.salesforce.com/us/developer/docs/apexcode/index.htm

 

 

SuvraSuvra

Hello All,

 

Thanks a lot fo your reply..this link is quite helpful. will get back to you in case further clarifications are required.

 

Thanks,

Suvra

SuvraSuvra

Hi All,

 

One more doubt regarding batch apex execution.

 

Is it possible to retain any state across different executions of a single batch??

e.g, I have one variable called index, which is initialised to 0. Now, within execution() method of batch apex class, i'm updating the variable value. I want the next execution() method to take the updated value of index while processing. But its again taking the value "0", as it was initialised.

 

any clue on this??

 

 

Thanks and Regards,

Suvra

J&A-DevJ&A-Dev
Using the link I provided, do a search on the term: "Using State in Batch Apex". There is a code snippet that describes what you're trying to achieve.