Created
March 31, 2015 17:07
-
-
Save Sunil02kumar/7a92f997d18f5e1b200f to your computer and use it in GitHub Desktop.
Finding Validation Rules using Tooling API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Apex Code: | |
HttpRequest req = new HttpRequest(); | |
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); | |
req.setHeader('Content-Type', 'application/json'); | |
String domainUrl=URL.getSalesforceBaseUrl().toExternalForm(); | |
system.debug('********domainUrl:'+domainUrl); | |
req.setEndpoint(domainUrl+'/services/data/v33.0/tooling/query/?q=Select+id,FullName,TableEnumOrId,ValidationName,Metadata+from+ValidationRule'); | |
req.setMethod('GET'); | |
Http h = new Http(); | |
HttpResponse res = h.send(req); | |
system.debug(res.getBody()); | |
String ss=res.getBody(); | |
Response will be in JSON format: | |
{ | |
"size": "22", | |
"totalSize": "22", | |
"done": "true", | |
"entityTypeName": "ValidationFormula", | |
"records": { | |
"attributes": { | |
"type": "ValidationRule", | |
"url": "/services/data/v33.0/tooling/sobjects/ValidationRule/03d900000007XP3AAM" | |
}, | |
"Id": "03d900000007XP3AAM", | |
"FullName": "SDRelationship__c.SDOC__GD_Link", | |
"TableEnumOrId": "01I90000000nEcaEAE", | |
"ValidationName": "GD_Link", | |
"Metadata": { | |
"errorConditionFormula": " | |
AND( | |
ISPICKVAL(SDOC__SDoc_Rel_GD_Status__c, 'Linked to Google Doc') | |
, | |
ISBLANK( SDOC__SDoc_Rel_GD_Link__c ) | |
)", | |
"errorMessage": "Before you are able to manually set the Docs Status to \"Linked to Google Doc\", you must first enter a valid URL to an existing Google Doc in the Google Docs Link field.", | |
"active": "true" | |
} | |
} | |
} | |
Here TableEnumOrId takes 15 or 18 digit id of custom object or API name of standard objects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment