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

Hi Friends,

Hi All,
By using soql we can retrieve the records 50,000, Now i have 60,000 records how to i can achive this.

Gaurav Gulanjkar 18Gaurav Gulanjkar 18

You should look at using Batch Apex to accomplish your goals.
You cannot retrieve more than 50,000 records your SOQL calls in a single context.
However, with  Batch Apex your logic will be processed in chunks of anywhere from 1 to 200 records in a batch.
You'd need to modify your business logic to take the batching into account if necessary.
jyothsna reddy 5jyothsna reddy 5
Hi viswsanath,

Using Batch apex to accomplish your goal.

Need of Batch Apex: - As you all might know about the salesforce governor limits on its data. When you want to fetch thousands of records or fire DML on thousands of rows on objects it is very complex in salesforce and it does not allow you to operate on more than certain number of records which satisfies the Governor limits.

But for medium to large enterprises, it is essential to manage thousands of records every day. Adding/editing/deleting them when needed.
Salesforce has come up with a powerful concept called Batch Apex. Batch Apex allows you to handle more number of records and manipulate them by using a specific syntax.
Advantages of using Batch Apex?
  • Higher Governor Limits
  • Can be used to process in batches
  • Can be scheduled to run at different time. (read more)
  • Work around to other governor limits e.g. Send More than 10 E-mails blog by Ankit Arora
      We have to create an global apex class which extends Database.Batchable Interface because of which the salesforce compiler will know, this class incorporates batch jobs. Below is a sample class which is designed to delete all the records of Account object (Lets say your organization contains more than 50 thousand records and you want to mass delete all of them).
global class deleteAccounts implements Database.Batchable
global final String Query;
global deleteAccounts(String q)
global Database.QueryLocator start(Database.BatchableContext BC)
return Database.getQueryLocator(query);
global void execute(Database.BatchableContext BC,List scope)
List <Account> lstAccount = new list<Account>();
for(Sobject s : scope)
 Account a = (Account)s;
Delete lstAccount;
global void finish(Database.BatchableContext BC)
                //Send an email to the User after your batch completes
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {‘’};
mail.setSubject('Apex Batch Job is done‘);
mail.setPlainTextBody('The batch Apex job processed ');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

Call the Batch class:

deleteAccounts b = new deleteAccounts();
//Parameters of ExecuteBatch(context,BatchSize)

Call the batch class using schedule Apex or anonymous block.

For more information about Batch Apex please follow the below link
I hope it will help you .

Jyothsna D