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.