# Write a SOQL query to fetch all active ValidationRule or CustomField metadata records using the Tooling API query structure.

**Topic:** Development · **Difficulty:** Hard · **Asked at:** Salesforce, Deloitte, Persistent · **Tags:** soql, scenario, tooling-api, metadata

Read it on the site: https://www.forcechallenges.com/interview-questions/write-a-soql-query-to-fetch-all-active-validationrule-or-customfield-metadata-records-using-the-tooling-api

## Answer

Metadata objects such as `ValidationRule` and `CustomField` are queried through the **Tooling API** (`/services/data/vXX.0/tooling/query/?q=...`), not the standard query endpoint.

```soql
SELECT Id, ValidationName, Active, EntityDefinition.QualifiedApiName FROM ValidationRule WHERE Active = true
SELECT Id, DeveloperName, TableEnumOrId FROM CustomField
```
Only `ValidationRule` has an `Active` flag; `CustomField` records are queried by name or object (there is no 'active' state for fields).

---
Source: ForceChallenges · last updated 2026-10-19
