SOQL is Salesforce’s object query language. It has familiar basic syntax to traditional database SQL syntax but with some noticeable differences. One of the biggest differences is that SOQL does not support wildcard in SELECT statements to query all fields from an object. For example, “SELECT * FROM object”. However, there is a workaround by using Dynamic SOQL and Apex Describe.

In the below example I show you how to query all fields from an object by exploiting the metadata available from the DescribeSObjectResult class.

Example 1: Query All Fields for a Known Record ID

View gist.

Example 2: Query All Fields for All Records

The same concept as above but we don’t have a specific record ID, so we need to determine the sobjectype by explicitly specifying the object we’ll query on.

View gist.

Next Steps

In addition to the resources linked above, check out these great tutorials to continue learning more about SOQL!