7

I'm trying to use the FIELDS(ALL) function in my apex test class, in order to prevent this kind of error

SObject row was retrieved via SOQL without querying the requested fields...

But I can't save class with such query, because of this error:

       The SOQL FIELDS function is not supported with an unbounded set of fields in this API.

  • Api version on test class 51
  • When I try to use the same query by dev console, it works fine.

Any thoughts?

enter image description here enter image description here

2
  • check your org version, because might be that your org is created with 50.0 version, plus you'll get duplicate field error for Id, FIELDS(ALL), it should be just FIELDS(ALL)
    – ytiq
    Jun 1, 2021 at 8:39
  • haha, yes, thanks :) Jun 1, 2021 at 10:23

1 Answer 1

11

It looks like an unbounded query is not currently supported in Apex. This query in your test class is considered an unbound query, hence the error.

Not sure why it doesn't fail in the dev console query editor. Maybe it uses the REST API behind the scenes (?)

https://developer.salesforce.com/docs/atlas.en-us.230.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_fields.htm

The API distinguishes bounded queries, which have well-defined sets of fields, from unbounded queries, which have sets of fields that the API can’t determine in advance. For example, because the number of custom fields for an object isn’t predetermined, FIELDS(CUSTOM) and FIELDS(ALL) are considered unbounded. This table shows the support for FIELDS() in bounded and unbounded queries:

Screeeshot of the table defining bounded vs unbounded

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .