I've been using the workbench to test queries that I'll later run through the Restforce Gem to pull data into a Rails app via the REST API.

The app is looking to build a report on a client object, then poll all of the connected records to return a complete report of all data we have relating to the client.

Generally this involves polling ~29 individual objects, each with around 10-25 fields but two/three with 200+. Additionally queries to some of these objects may yield a high number of records. I've been achieving this with queries like the one below (all examples are illustrative not our real objects!)

SELECT Id, Name, 
       (SELECT Id, Name FROM Client_Information__r),
       (SELECT Id, Name FROM Client_Interactions__r),
       (SELECT Id, Name FROM Client_Details__r),
       (SELECT Id, Name FROM Client_Attendances__r),
       (SELECT Id, Name FROM Client_Training_Sessions__r) 
FROM Contact 
WHERE UID__c = 'ID101'

However in order to minimize the number of API calls we have to make i've been attempting to integrate in all the fields we need with code as follows:

relationships_string = "Id, Name, example_field__c ... blah_blah__c"

SELECT Id, Name, 
       (SELECT #{relationships_string} FROM Client_Information__r),
FROM Contact 
WHERE UID__c = 'ID101'

This should be working but I think the number of fields I'm polling is tipping me over some of the API limits. Specifically if I put one of these queries into the workbench I get an error code "Unknown Asynchronous State". I have a suspicion this is because i'm requesting too much data at once. To run this through an app I'm also having "HTTP 413 - Request Entity Too Large" returned.

Has anyone else had this problem with this kind of rest request via the workbench?

Unless someone has a smart work-around I guess I'll have to write a digester and reassembler to break this down into smaller API queries... but I'm unsure how big I should be making that.

Looking at the limits guide I can't tell if I am running up against the "Total number of records retrieved by SOQL queries" limit (50,000) or one of the other ones.

How might i tell so I can go about designing the best way to digest these records?

  • 1
    Max batch size of records retrieved in one API call is typically 2000 per query. More likely it is this you are encountering. Number of fields won't typically matter, but number of rows will certainly matter. Especially when you consider the rows in sub queries count.
    – pchittum
    Mar 10, 2015 at 13:41
  • Thanks that's really useful to know - do you have a reference for that so I can read around it? Also, given i don't know how many records might be on the other end of a query (any of our clients may have one 'encounter' record or 2500 on just a single object)... what is the recommended strategy for decomposing these into smaller queries... guessing there's not a .paginate method I could chuck in to the mix?
    – Huw
    Mar 10, 2015 at 13:56


You must log in to answer this question.

Browse other questions tagged .