May 18, 2017

How to query all Validation Rules with object names in Salesforce?

Sample SOQL:

SELECT ValidationName, Active, EntityDefinition.DeveloperName FROM ValidationRule


Note:
When you use Developer Console, use Tooling API to query.

For more fields, check the below link

https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_validationrule.htm

6 comments:

  1. Hi, How do we query all validation rules for all objects in an org, the objective is to extract all the validation rules for all the objects(standard and custom) to excel

    ReplyDelete
    Replies
    1. Use Developer Console and query it. Press CTRL + A and copy the contents. Paste it in a excel file.

      Delete
  2. Hi Magulan,
    Thanks for your response, I have used below query in REST Explorer
    query?q=Select+Id,Active,Description,EntityDefinition.DeveloperName,ErrorConditionFormula,+ErrorMessage+From+ValidationRule
    When I am using the above query in REST Explorer, I am getting below INVALID_FIELD message: EntityDefinition.DeveloperName,ErrorConditionFormula, ErrorMessage ^ ERROR at Row:1:Column:61 No such column 'ErrorConditionFormula' on entity 'ValidationRule'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. errorCode: INVALID_FIELD

    I am still bit new to SF world :)

    ReplyDelete
    Replies
    1. ErrorConditionFormula is not supported.
      Also remove EntityDefinition.DeveloperName.
      https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_validationrule.htm

      Delete
  3. thanks..I thought so 'Query this field only if the query result contains no more than one record. Otherwise, an error is returned. If more than one record exists, use multiple queries to retrieve the records. This limit protects performance.' But is there a way where I can retrieve callout bulk HTTP Get Requests if I have the Validation record Ids..eg:
    /services/data/v48.0/tooling/sobjects/ValidationRule/XXXXXXXXXXXXwUQAS
    /services/data/v48.0/tooling/sobjects/ValidationRule/XXXXXXXXXXXXXXVQAS
    /services/data/v48.0/tooling/sobjects/ValidationRule/XXXXXXXXXXXXX8QAC

    or a way to goto the URL..https://xxxxxxxx.my.salesforce.com/xxxxxxxxxxxxwVQAS for each record and grab the fields and its Values.
    Somehow your replies are not coming to my email :), I had to visit the page to check for your response:)

    ReplyDelete
    Replies
    1. You can try composite request if you have series of callouts.
      https://help.salesforce.com/articleView?id=000317519&language=en_US&type=1&mode=1
      Check this for example - https://www.infallibletechie.com/2020/06/fetching-validation-rule-from-tooling.html

      Delete