Fetching All Fields in Salesforce – Spring 2021 Edition

Sharing is Caring

In Salesforce, the Standard Query Language (SQL) didn’t have a great way of doing SELECT * or select all fields but that changed in Spring 2021.

In the past, we had to create a library and write a lot of code to potentially get all of the fields. You can see an example of it in my post How to Select All Fields in SOQL.

For the Spring 2021, we no longer need to do that!

  • FIELDS(ALL) – This fetches all the fields of an object at one go. This is similar to * operator in SQL query.
  • FIEDLS(STANDARD) – This can be used to fetch all the standard fields of an object at one go.
  • FIELDS(CUSTOM) – This is use to fetch all the custom fields alone on an object.

To use this, we just need to change our query to be something like this:

List<Account> accounts = [SELECT FIELDS(ALL) FROM Account LIMIT 200];

Keep in mind that there are still limits on the number of records that can be queried.

Sharing is Caring

Brian is a software architect and technology leader living in Niagara Falls with 13+ years of development experience. He is passionate about automation, business process re-engineering, and building a better tomorrow.

Brian is a proud father of four: two boys, and two girls and has been happily married to Crystal for more than ten years. From time to time, Brian may post about his faith, his family, and definitely about technology.