I have 3,000,000 records for contacts.I wanted to retrieve the records in a batch with a count of 10000.Can I write a query like this

Select Id,Name from Contact limit 10000 offset 20000.

Is this efficient.Moreover will offset and limit keywords work for records in huge number

  • in SOQL offset limit is 2K. You can't give more than that. If you are using batch class then it will get all the 3 millions of records and execute all the records based on the batch size
    – Ratan Paul
    Commented Sep 26, 2017 at 11:29

2 Answers 2


LImit on records A maximum of 50 million records can be returned in the Database.QueryLocator object. If more than 50 million records are returned, the batch job is immediately terminated and marked as Failed.

OFFSET LIMITATION The SOQL offset limits can be increased refer link https://help.salesforce.com/articleView?id=000232691&type=1.


Offset: The maximum offset is 2,000 rows(returned result). Requesting an offset greater than 2,000 will result in a NUMBER_OUTSIDE_VALID_RANGE error.

Limit: There is no restriction on limit. It's limited to the context in which it's used. If it's used in Apex code it's limited to the total governor limit for SOQL rows, which is currently 50,000. If it's used in a query via the Web Service API then there is no limit.

The issue you're running into appears solely to be an issue with using the OFFSET clause and LIMIT together.

Check the following link for Limit,Offset workaround: Workaround for Offset 2000 limit on SOQL Query

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .