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
karthikeya 2karthikeya 2 

SOQL query for fetching 2nd record?

Hello every one,

how to fetch 2nd record by SOQL query, with out using  offset.

my qyery: select id,createdDate,End_Date__c,Employee__c from Organization__c where ahm__Employee__c = 'a0Z37000001xwfP' order by CreatedDate DESC limit 1 offset 1

but with out using offset , because batch class will not accept the offser.

Thanks in advance.
Balayesu ChilakalapudiBalayesu Chilakalapudi
You can use executeBatch(batchClassObject, scope) of Database class to specify batch size in the scope. If you give scope value as 1, second record will be fetched after processing first record.

Ex:  Database.executeBatch(yourbatchclassobject, 1);

Specify your query as

select id,createdDate,End_Date__c,Employee__c from Organization__c where ahm__Employee__c = 'a0Z37000001xwfP' order by CreatedDate DESC limit 1

Let us know if it helps.