Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I need to query all the available fields for an object, but retrieving each object one at a time via the REST API is not an option.

// Not feasible
for each account record
   https://salesforce/services/data/version/sobjects/account/id

Currently, I'm grabbing the metadata for the object, and iterating through the fields to build the SOQL query.

// I.e.
for each field in the metadata
  soql += columnName + ','

submit soql query to SF

This was working okay, until I started working with objects that contain hundreds of fields (in my case, the Account object is one of them). When submitting such a large query (~12,500 characters long) I'm getting a Request Entity Too large, code 413 error.

I'm not sure how to go about this. In the worst case scenario, I can divide the SOQL into different parts and later join the values. For example, when the SOQL has reaced ~6,000 characters, fire it off and continue iterating over the columns to build another SOQL query, which later would be joined together to form a single dataset.

Does anyone have any ideas or guidance on how to handle this issue?

share|improve this question
    
I've hit that limit previously and took the very same approach like yours. It's been a couple of years and the code still works fine. Let's see if someone's got a better way of doing this. –  Bachovski Aug 20 at 23:17

2 Answers 2

Rather than sending the query to the rest method, why not just send the object type to a specific endpoint that is set to query the entire record. Then in the class for that endpoint, have the class do all the work.

share|improve this answer
    
I understand what you're referring to. In our PhoneGap application, it might be a bit much to construct a new end point to handle this scenario. –  contactmatt Aug 21 at 16:57
    
In the POST method for the endpoint say /queryAll/* or whatever you call it, pass in the Name of the object only. Then in the method in build the dynamic query using apex based on the object name passed in, do the query and return the results. I realize that this creates another endpoint but it would allow you to get the results back in a single call and reduce the manipulation on the calling side. –  Eric Aug 21 at 17:04

A method to keep the soql string a bit shorter could be to exclude some unnecessary for the special use case. Usually I now that I want all fields except e.g. lastActivityDate or other readonly stuff - but does not help if you really need all.

Or you could use shorter field names - but that's also silly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.