Fetch All Fields In SOQL Query | Spring 21 New Feature
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.Here is how the query will look like -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];BOUNDED AND UNBOUNDED QUERIESWhen 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)...
Read More