

Sudipta Deb
Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect
If you worked with SQL or any other query language before, you probably familiar with Select * from …, right? This is the way to fetch all fields from a particular table in other(mostly all) query languages. But in the Salesforce world, we were not having this feature. In SOQL, there is nothing with which we can fetch all the fields unless we specifically mention all the field names in the query.
But now in Spring 21, Salesforce is bringing a function through which we can fetch all fields in SOQL Query.
We have now FIELDS(ALL), FIELDS(STANDARD), and FIELDS(CUSTOM) which we can use in the SOQL query.
- FIELDS(ALL) – This fetches all the fields of an object. This is similar like Select * from SQL.
- FIELDS(STANDARD) – This fetches all standard fields of an object.
- FIELDS(CUSTOM) – This fetches all custom fields of an object.
List<Contact> allConatcts = [SELECT FIELDS(ALL) FROM CONTACT LIMIT 200];In Subqueries, it will look like –
List<Account> allAccounts = [SELECT Account.Name, (SELECT FIELDS(ALL) FROM Account.Contacts LIMIT 200) FROM Account];The form you have selected does not exist.
Bounded And Unbounded Queries
When API cannot determine the set of fields in advance, then it will consider query as Unbounded Query, other if API can determine the set of fields in advance, then it is Bounded Query. For example – The number of custom fields for an object is not pre-determined, so FIELDS(CUSTOM) and FIELDS(ALL) are considered as Unbounded Query. The below table is a good reference to understand how these functions will work w.r.t bounded and unbounded queries.

Limitation
- Fetching more than 200 records per query is not allowed.
Best Practice
Disclaimer
This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.



Hi..Will this feature work for in Apex Class?
select fields(standard) will
https://1.bp.blogspot.com/-F4KFfhhRmo0/YASo-7ACDbI/AAAAAAABVXw/dVAUt-_MHAUBqkvsRioQwFsUmbvuFLfCwCLcBGAsYHQ/s1714/Image.png
Russ Spears is correct. I have added the section "BOUNDED AND UNBOUNDED QUERIES" which will explain which is available in Apex.