How to Query/Report on Metadata in Your Salesforce Org

An Easier Way to Find Out about Metadata in Your Salesforce Org

As a Salesforce Admin or Consultant, you may want to find out about the metadata in your Salesforce Org from time to time. For example, how many custom objects are there, what are the fields in the custom objects, how many triggers are there in your org, how many of those are inactive, how many Apex classes are there, how many of those are from managed packages, and so on.

The most common way to find these things out will be to log in to your Salesforce Org, navigate to setup, go to each of the sections individually and then gather the information. But this is a labor-intensive, manual, and time-consuming exercise. There is a better way...

Rather than sifting through all the different options in your setup menu, you can use simple English to get the information you want in no time. And we are going to do this using the Developer Console, the Tooling API, and a SOQL query. Now before you freak out and start thinking this is not for you, stay with me and let me show you how easy this is going to be.

We are going to write a query in simple English to retrieve the information. This simple query in English is known as SOQL (which stands for Salesforce Object Query Language). We will be writing and executing this query in the Developer Console. So the Developer Console becomes our UI, or user interface. And this query will be executed using the Tooling API and will retrieve the results of the query. This happens behind the scenes so you don't really need to worry about this. With these three things in your arsenal, there is absolutely no need to manually scan the entire Salesforce org, and you have just saved yourself quite a lot of time and effort. :-)

So, here is a step-by-step guide on how to query/report on metadata in Salesforce, and I believe this can be helpful and beneficial for everyone, especially Salesforce Admins and Consultants who deal with metadata all the time.

  • Create a Simple SOQL Query

  • Create a Complex SOQL Query

  • Export Query Results to Excel

  • Review Available Tooling API Objects

It won't take you more than 10–15 minutes to understand how this works, so let's dive right in.

References & Useful URLs