Howto wildcard SELECT * to query all fields of objects in APEX?

  • I have created sObject and I need all the fields and I have many. Is there a way I can directly get all of them rather then typing each one of them.

    you got lots of great suggestions here. Note that some fields have restrictions from being selected in the dynamic SOQL when more than one row can be returned - notably fields of type base64 such as Attachment.body

    As of the Spring '21 release this is possible using FIELDS( ALL )! You might want to update the accepted answer

  • greenstork

    greenstork Correct answer

    7 years ago

    Update: Spring '21 Release (API v51+) adds new SOQL FIELDS function can select all fields of an object. Refer to documentation

    Knowing that new FIELDS function must have a LIMIT of at most 200, when used with ALL or CUSTOM keyword, the workaround below can still be useful.


    There is no way to Select * with SOQL.

    You can however work-around this limitation by using dynamic SOQL and describe methods to get all of the fields on the object. This is described in detail in this post by Cory Cowgill:

    Building Dynamic SOQL - Select All Query

    You can't use `FIELDS(ALL)` or `FIELDS(CUSTOM)` in Apex even with a `LIMIT` clause. These new features are essentially useless in Apex, as far as I can see.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM