In Salesforce, validation rules ensure data security by restricting certain data entries or specific business logic when users try to create or update records. In Salesforce, while working with validation rules, we often need to get the list of validation rules to clean up data or to fetch information regarding the validation rules.
In this Salesforce tutorial, I will explain how to query the Validation rules in Salesforce with the help of examples.
Query Validation Rules in Salesforce
To query the Salesforce validation Rules, navigate to the Salesforce developer console and enter the code below in the query editor.
Ensure that you have selected the checkbox Use Tooling API.
To query all the validation rules in your org, execute the query below in the developer console’s query editor.
SELECT Id, ValidationName, Active, Description, EntityDefinition.DeveloperName,
ErrorDisplayField, ErrorMessage,LastModifiedDate,CreatedDate FROM ValidationRuleAfter executing the above query in the query editor, we will see the existing validation rules in the output.

This way, we can query the validation rules in Salesforce using SOQL.
When you need to query details like metadata error conditions, you can only query one result by providing the ID of that specific validation rule. Otherwise, it will return the Malinformed_Query error.

The correct way to query the error condition of the validation rule is mentioned in the below SOQL query, where I have entered the ID of the specific validation rule.
SELECT Id, ValidationName, Metadata, Description, EntityDefinition.DeveloperName, ErrorDisplayField, ErrorMessage
FROM ValidationRule
WHERE Id = '03dJ3000000GsKdIAK'Output:

When we need to query the validation of any standard or custom Salesforce object, then we will use EntityDefination.DeveloperName with the WHERE clause in the SOQL query.
For example, to query the validation rules of the “Account” object, we will execute the SOQL query in the following way.
SELECT Id, ValidationName, Description, EntityDefinition.DeveloperName, ErrorDisplayField, ErrorMessage
FROM ValidationRule
WHERE EntityDefinition.DeveloperName = 'Account'Output:

This way, we can query the validation rules for the specific objects in Salesforce by following the above method. Just make sure that you have enabled the checkbox Using Tooling API.
You may also like to read:
- Query Activity Related To Fields With SOQL in Salesforce?
- Query Tasks, Notes, Attachments by Object Type using SOQL in Salesforce
- Query SOQL NOT LIKE Operator in Salesforce
- Query Salesforce Picklist Field values using SOQL
- Query Records Created Today or Yesterday with SOQL in Salesforce

Abhijeet is a skilled Salesforce developer with experience in developing and integrating dashboards, data reports, and Salesforce applications. He is also skilled at optimizing processes and flow automation processes, coding, and executing complex project architecture. Read more about us | LinkedIn Profile.