+ Start a Discussion
Guna P 3Guna P 3 

How to retrieve all contacts with paging through REST api?

I want to retrieve all contacts with paging support. Such that my organizaion has 7000 contacts, I need to read 100 contcats per api call with paging support. How to accomplish this using SSQL through REST API?

I'm using this api:
https://ap5.salesforce.com/services/data/v42.0/query?q=SELECT Id,FirstName,LastName FROM Contact

Same paging support need for all the modules: leads, accounts, notes, events and tasks etc.


If the initial query returns only part of the results, the end of the response will contain a field called nextRecordsUrl

Please review this link - https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query.htm

Laxmi N 6Laxmi N 6
How to fetch all the fields of contact using the rest API?
Select * from Contact gives a MALFORMAED Querry error.
PS: I want the data and not meta data.
Irshaad Jaunbocus 9Irshaad Jaunbocus 9
Hi Laxmi,

Since we cannot use Select * in SOQL, I built something similar in my Apex class using the schema class for case object.

 DescribeSObjectResult describeResult = Case.getSObjectType().getDescribe();    
 List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() );    
 String query =      ' SELECT ' +          String.join( fieldNames, ',' ) +      ' FROM ' +          describeResult.getName() + ' Limit 5000'    ;    
 // return generic list of sobjects or typecast to expected type    
List<SObject> records = Database.query( query );    

Hope this helps.