1

I need to retrieve all the validation rules associated with a given object, using the REST API.

Looking in doc/forums, I've found that I could retrieve validation rules associated with an object using the following query:

https:///services/data/v35.0/tooling/query?q=Select Id,Active,Description,ErrorDisplayField, ErrorMessage From ValidationRule Where EntityDefinitionId = 'xxxxx'

The problem is that I don't have the object'ID needed to filter, I only have its name. Is there any way to filter using the object's name?

Another alternative seems to be getting the object'ID, but it seems that Metadata REST API (i.e. describe) does not return it.

Any help on this is very appreciated.

Mariana

1

1 Answer 1

1

Please use the below solution in workbench via REST explorer & method as "GET".

/services/data/v43.0/tooling/query?q=Select+Id,Active,Description,EntityDefinition.DeveloperName,+ErrorMessage+From+ValidationRule+where+EntityDefinition.DeveloperName+=+'Lead'

Or you can you simple use below SOQL query having Tooling API enabled -

Select Id,ValidationName, Active,Description,EntityDefinition.DeveloperName,ErrorDisplayField, ErrorMessage From ValidationRule where EntityDefinition.DeveloperName='Lead'

Thanks!

2
  • ErrorConditionFormula is not a field available on the ValidationRule object. My guess is you'll have to individually query validation rules and then use the ErrorConditionFormula field from the associated metadata Commented Mar 7, 2023 at 14:32
  • To get the errorConditionFormula there is a workaround. Run below code in Anonymous Window HttpRequest req = new HttpRequest();req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); req.setHeader('Content-Type', 'application/json');String domainUrl=URL.getSalesforceBaseUrl().toExternalForm();string query='Select+id,FullName,createdDate,TableEnumOrId,ValidationName,Metadata+from+ValidationRule';req.setEndpoint(domainUrl+'/services/data/v33.0/tooling/query/?q='+query);req.setMethod('GET');Http h = new Http();HttpResponse response = h.send(req);system.debug(response.getBody()); Commented Nov 6, 2024 at 10:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.