You need to sign in to do that
Don't have an account?
Simon234
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?
@HttpGet 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(); totalList.add(t); } 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++) { currentList.add(totalList.get(i)); } res.responseBody = Blob.valueOf(JSON.serialize(currentList)); return currentList; }
After some research found below link for similar discussion see if tha can help you.
https://salesforce.stackexchange.com/questions/240430/how-to-make-httpget-service-pagination-with-a-limit-of-a-million-or-more?rq=1
Best Regards,
Sandhya