+ Start a Discussion

How to make correct pagination for HttpGet service?

I have a callout and batch on other side. Where do I need define steps and listsize: here or there? How to do it right?
    global static List<Tool__c> getTool(){
        RestRequest req = RestContext.request;
        RestResponse res = new RestResponse();
        RestContext.response = res;
        Integer lastIndex = 400;  //I want make last index
        Integer listSize = 200;  //and size for 1 page
		//So I want to get 2 steps of 200 records till 400th record.
		//But I get only 200 on callout's side.
        Database.QueryLocator q = Database.getQueryLocator([SELECT Name, Price__c FROM Tool__c]);
        Database.QueryLocatorIterator iterator =  q.iterator();
        List<Tool__c> totalList = new List<Tool__c>();
        while (iterator.hasNext()) {
            Tool__c t = (Tool__c)iterator.next();
        List<Tool__c> currentList = new List<Tool__c>();
        Integer last_i;
        if((lastIndex + listSize) <= totalList.size()) {
            last_i = lastIndex + listSize;
        } else{
            last_i = totalList.size();
        for(Integer i=lastIndex; i<last_i; i++) {
        res.responseBody = Blob.valueOf(JSON.serialize(currentList));
        return currentList;

SandhyaSandhya (Salesforce Developers) 

After some research found below link for similar discussion see if tha can help you.

Best Regards,