[SalesForce] Recommended way to query all the fields for an object type in a SOQL query

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?

Best Answer

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.

Related Topic