What is the Tooling API?
- Tooling API exposes metadata information of Org
- We can access Metadata information using REST or SOAP.
- A Simple use case of tooling api is deleting the debug log from the developer console
What Can be fetch using Tooling API?
- Fetch the metadata about Visualforce Pages, Apex Triggers, Apex classes.
- Get the metadata about an object’s field.
- Get the Code Coverage details of Apex Classes and Triggers.
- Retrieve metadata of custom and standard object properties.
- Retrieve metadata information about Validation Rules and Workflow Rules.
- We can Create, Update Apex Classes and Apex Triggers.
- We can get the RecentItems of our dev-org using Tooling API.
Where can Tooling API be used?
Because Tooling API allows you to change just one element within a complex type, it can be easier to use than Metadata API. Other use cases include:
- Source control integration
- Continuous integration Ex- Jenkin used tooling api for code coverage validation.
- Apex classes or trigger deployment
How can Tooling API consume?
Using Apex Code
Tooling API can be consumed using HTTP REST API and SOAP method
- HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); //Get user Session ID
req.setHeader('Content-Type', 'application/json');
String SFdomainUrl=URL.getSalesforceBaseUrl().toExternalForm();
String query='Select+id,FullName,createdDate,TableEnumOrId,ValidationName,Metadata+from+ValidationRule';
req.setEndpoint(SFdomainUrl+'/services/data/v33.0/tooling/query/?q='+query);
req.setMethod('GET');
Http h = new Http();
HttpResponse response = h.send(req);
Using Workbench
Using the Developer Console
Check Use tooling API while querying the Apex Test class or Debug log
No comments:
Post a Comment