How to Query Metadata Salesforce with Examples

Salesforce metadata is a crucial component that facilitates platform customization and management. It refers to data that defines other data, such as the structure of custom objects, fields, and page layouts.

Query metadata is a powerful tool for developers and administrators. It enables them to retrieve metadata information to perform some logic or know how much metadata on the system is.

How to Query Metadata Salesforce

Query Metadata using SOQL

Here is a list of the most helpful metadata you can query using an SOQL. Some of them require to enable ToolingAPI on the Developer Console.

Tooling API in Salesforce, querying metadata

Query Object Metadata


Objects represent the data tables in Salesforce, and this query retrieves the Account Object's Id and DeveloperName.

SELECT Id, DeveloperName FROM EntityDefinition WHERE QualifiedApiName = 'Account'

Object Field

This query fetches fields within the Account object, returning their Ids and DeveloperNames.

SELECT Id, DeveloperName FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Account'

Custom Field

Custom fields are user-defined fields in Salesforce objects; this query lists them along with their Object.

SELECT Id, DeveloperName, EntityDefinition.QualifiedApiName FROM CustomField
Enable ToolingAPI

Field Set

Field Sets are collections of fields typically used in Visualforce pages. This query retrieves the API Names of Field Sets.

SELECT DeveloperName FROM Fieldset
Enable ToolingAPI

Validation Rule

Validation Rules ensure data quality. This query provides the names of Validation Rules.

SELECT ValidationName FROM ValidationRule
Enable ToolingAPI

Page Layout

Page Layouts define the arrangement of fields on a Salesforce record page. This query returns the names of Page Layouts.

Enable ToolingAPI

Record Type

Record Types define different record structures. This query lists Record Type API Names and their associated SObject.

SELECT DeveloperName, SobjectType FROM RecordType

Quick Action

Quick Actions allow users to perform tasks quickly. This query fetches the API Names of Quick Actions.

SELECT DeveloperName FROM QuickActionDefinition
Enable ToolingAPI

Query Processes Metadata

Apex Class

Apex Classes contain custom logic. This query returns the names of Apex Classes.

SELECT Name FROM ApexClass


Apex Triggers execute custom logic before or after records are saved. This query provides Trigger names and their related objects.

SELECT Name, TableEnumOrId FROM ApexTrigger

Workflow Rule

Workflow Rules automate standard internal procedures. This query retrieves the names of Workflow Rules.

SELECT Name FROM WorkflowRule
Enable ToolingAPI

Flow and Process Builder

Flow and Process Builder automate processes in Salesforce. This query shows Flow/PB names and Process types.

SELECT MasterLabel, ProcessType FROM Flow
Enable ToolingAPI

Approval Process

Approval Processes manage the approval of records. This query fetches API Names of Approval Processes.

SELECT DeveloperName FROM ProcessDefinition

Email Template

Email Templates are used for outbound communications. This query lists Email Template names and API Names.

SELECT Name, DeveloperName FROM EmailTemplate

Query UI Components Metadata

Visualforce Page

Visualforce Pages are custom UIs. This query returns the names and markup of Visualforce Pages.

SELECT Name, Markup FROM ApexPage

Lightning Page

Lightning Pages are customizable Lightning Experience pages. This query fetches Ids and API Names of Lightning Pages.

SELECT Id, DeveloperName FROM FlexiPage
Enable ToolingAPI

Visualforce Component

Visualforce Components are reusable building blocks. This query retrieves names and markups of Visualforce Components.

SELECT Name, Markup FROM ApexComponent

Lightning Component

Lightning Components improve and customize the UIs. This query provides Ids and Names of Lightning Components.

SELECT Id, DeveloperName FROM LightningComponentBundle
Enable ToolingAPI


Reports display data in a tabular or graphical format. This query returns Report names and API Names.

SELECT Name, DeveloperName FROM Report


Dashboards provide real-time insights. This query fetches API Names of Dashboards.

SELECT DeveloperName FROM Dashboard

Query Permissions Metadata


Profiles define user permissions. This query lists Profile names.

SELECT Name FROM Profile

Permission Set

Permission Sets grant additional permissions. This query retrieves Permission Set names.

SELECT Name FROM PermissionSet

Permission Set Group

Permission Set Groups organize Permission Sets. This query fetches Ids and API Names of groups.

SELECT Id, DeveloperName FROM PermissionSetGroup

User Role

User Roles define the hierarchy. This query returns User Role names.


User Group

User Groups categorize users. This query lists User Group names.


Query Settings Metadata

Static Resource

Static Resources are used to store content such as images or files. This query retrieves Names and Content Types.

SELECT Name, ContentType FROM StaticResource

Remote Site Setting

Remote Site Settings enable external site access. This query fetches Site Names and Endpoint URLs.

SELECT SiteName, EndpointUrl FROM RemoteProxy
Enable ToolingAPI

Apex Log

Apex Logs track code execution. This query provides Log User Ids and Start Times.

SELECT LogUserId, StartTime FROM ApexLog

Custom Label

Custom Labels store text for translation. This query lists Custom Label Ids and Names.

SELECT Id, Name FROM CustomLabel

Custom Setting

Custom Settings store custom data. This query retrieves Custom Setting names.

SELECT Name FROM YourCustomSetting__c

Custom Metadata

Custom Metadata Types define custom application metadata. This query lists Custom Metadata API Names.

SELECT DeveloperName FROM YourCustomMetadataType__mdt


Organizations represent Salesforce instances. This query fetches Organization Names and Instance Names.

SELECT Name, InstanceName FROM Organization