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
Aakanksha Singh 11Aakanksha Singh 11 

How to retrieve more than 50k/1 million records through apex class in salesforce

Hello Everyone,

I want to know the possible ways through which we can fetch more than 50k/1million records through apex class in salesforce.

Please respond.

Thanks in advance.

Rregards
Aakanksha Singh
Best Answer chosen by Aakanksha Singh 11
Aakanksha Singh 11Aakanksha Singh 11
We have to use REST API for this.

All Answers

DeveloperSudDeveloperSud
Hi Aakansha,

You cannot retrieve more than 50,000 records your SOQL calls in a single context.Batch Apex is the only answer.
However using @readonly annotation can allow you to query up to 1 Million SOQL Rows but those records will be read only and you will not be 
able to perform any DML operation on those records.You can refer the below link for batch apex.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm
Aakanksha Singh 11Aakanksha Singh 11
Hello DeveloperSud,

Thanks for replying!!

I retrived data through batch apex,  bt neither I'm able to access its variable in another class nor assigning the value to the static variable of another class. You can refer to the following link: https://developer.salesforce.com/forums/ForumsMain?id=9060G000000I9BRQA0

Further I'm also trying to work through REST API, if you have any idea regarding these, please reply soon'

Thank You 
Aakanksha Singh
Aakanksha Singh 11Aakanksha Singh 11
We have to use REST API for this.
This was selected as the best answer
ranga babu vangalapudi 2ranga babu vangalapudi 2
@Aakanksha Singh can you please help me, i want to know how you retrieve 5OK/1 M recrods using REST API