A blog about Salesforce CRM Configuration and development

Saturday, 23 June 2018

Salesforce - Tooling API ( How to retrieve Metadata Information using Tooling API )

Tooling API:

Tooling API exposes metadata information of Org, we can access Metadata information using REST or SOAP. Tooling API retrieve the small piece of metadata, we can use this to develop an interactive application or tools for developers.

We can accomplish following tasks using Tooling API.:
  • Retrieve metadata about an object’s field.
  • Retrieve metadata of custom and standard object properties.
  • Get metadata information about Apex Classes, Visualforce Pages, Apex Triggers.
  • Get Code coverage details of Apex classes and Trigger.
  • Retrieve metadata information about ValidationRule and WorkflowRules.
  • Query RecentItems used in your SFDC org.
  • Etc...
In this blog, I am going to retrieve Metadata information about ValidationRule and WorkflowRule. I am using REST (GET) method here to make a callout.

HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); //Get user Session ID
req.setHeader('Content-Type', 'application/json');
String domainUrl=URL.getSalesforceBaseUrl().toExternalForm();
string query='Select+id,FullName,createdDate,TableEnumOrId,ValidationName,Metadata+from+ValidationRule';
//string query='Select+id,Name+from+WorkflowRule'; //use this query to get Workflow Rule
Http h = new Http();
HttpResponse response = h.send(req);

JSON Response:

"size": 1,
"totalSize": 1,
"done": true,
"queryLocator": null,
"entityTypeName": "ValidationRule",
"records": [
"attributes": {
"type": "ValidationRule",
"url": "/services/data/v33.0/tooling/sobjects/ValidationRule/03df40000002gPOAAY"
"Id": "03df40000002gPOAAY",
"FullName": "Account.Account_Name_not_starts_with_Test",
"CreatedDate": "2018-06-15T05:41:21.000+0000",
"TableEnumOrId": "Account",
"ValidationName": "Account_Name_not_starts_with_Test",
"Metadata": {
"description": null,
"errorConditionFormula": "CONTAINS(Name, 'Test')",
"errorDisplayField": null,
"errorMessage": "Account name should not contains Test",
"urls": null,
"active": true

We can parse this JSON response according to our requirements.

The Tooling API Objects. https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/reference_objects_list.htm

For more information on this please refer this link



  1. It's so nice article thank you for sharing a valuable content. google cloud online course

  2. Am getting [{"message":"This session is not valid for use with the REST API","errorCode":"INVALID_SESSION_ID"}] error

  3. Thank you so much for sharing this worth able content with us. The concept taken here will be useful for my future programs and i will surely implement them in my study. Keep blogging article like this.
    Best CRM System


Trailhead Profile

Follow by Email

Total Pageviews


Popular Posts

Powered by Blogger.

Contact form


Email *

Message *