Newer Version Available
Use Tooling API with REST
Resources
Use REST API if you’re using a language that isn’t strongly typed, like JavaScript. The Tooling REST API can be used just like the Force.com REST API; for details on usage, syntax, and authentication, see the Force.com REST API Developer's Guide.
This section lists supported REST resources in Tooling API.
The base URI for each Tooling REST API resource is http://domain/services/data/vXX.X/tooling/ where domain is a Salesforce instance or a custom domain and vXX.X is the API version number. For example: http://na1.salesforce.com/services/data/v28.0/tooling/
Like the Force.com REST API, Tooling API uses the following resources.
| URI | Supported Methods | Description |
|---|---|---|
|
/completions?type= |
GET |
Retrieves available code completions of the referenced type. Currently only supports Apex system method symbols (type=apex). Available from API version 28.0 or later. |
|
/executeAnonymous/?anonymousBody= <url encoded body> |
GET |
Executes Apex code anonymously. Available from API version 29.0 or later. |
|
/query/?q= |
GET |
Executes a query against a Tooling API object and returns
data that matches the specified criteria. If the query results are too large, the response contains the first batch of results and a query identifier. The identifier can be used in a request to retrieve the next batch. |
|
/runTestsAsynchronous/?classids= <comma separated list of class IDs> |
GET |
Executes the tests in the specified classes. Running tests asynchronously allows methods to process in parallel, cutting down your test run times. |
or |
POST |
Runs one or more methods within one or more Apex classes, using the asynchronous test execution mechanism. <tests array> is an array of objects, each with two parameters: classId and testMethods. The classId parameter is a String holding a test class’s ID. The testMethods parameter is an array of Strings, each containing the name of a test method in the test class. Each class ID can be listed only once. Multiple occurrences of a test method name in a testMethods array are ignored. Test methods that don’t exist are skipped. A null or missing testMethods array specifies that all test methods in the test class are run. Example <tests
array>:
|
|
/runTestsSynchronous/?classnames= <comma-separated list of class names> |
GET |
Executes the tests in the specified classes using the synchronous test execution mechanism. |
|
/sobjects/ |
GET |
Lists the available Tooling API objects and their metadata. |
|
/sobjects/SObjectName/ |
GET POST |
Describes the individual metadata for the specified object or creates a record
for a given object.
|
|
/sobjects/SObjectName/describe/ |
GET |
Completely describes the individual metadata at all levels for the specified
object. For example, use this resource to retrieve the fields, URLs, and child relationships for a Tooling API object. |
|
/sobjects/SObjectName/id/ |
GET PATCH DELETE |
Accesses records based on the specified object ID. Use the GET method to retrieve records or fields, the DELETE method to delete records, and the PATCH method to update records. |
|
/sobjects/ApexLog/id/Body/ |
GET |
Retrieves a raw debug log by ID. Available from API version 28.0 or later. |
- /sobjects/SObjectName/ (POST method)
- /sobjects/SObjectName/id/ (PATCH and DELETE methods)
By default, if AllOrNoneHeader isn’t used, REST calls can save a partial set of records for records with no errors (equivalent to AllOrNoneHeader=false). If AllOrNoneHeader is set to true, records are saved only when there are no failures in any record in the request.
Examples
The following examples use Apex to execute REST requests, but you can use any standard REST tool to access Tooling REST API.
1HttpRequest req = new HttpRequest();
2req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
3req.setHeader('Content-Type', 'application/json');1Http h = new Http();
2HttpResponse res = h.send(req);
3system.debug(res.getBody());1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/sobjects/');
2req.setMethod('GET');1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/sobjects/
2TraceFlag/');
3req.setMethod('GET');1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/sobjects/
2TraceFlag/describe/');
3req.setMethod('GET');1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/sobjects/
2MetadataContainer/');
3req.setBody('{"Name":"TestContainer"}');
4req.setMethod('POST');1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/sobjects/
2MetadataContainer/ + containerID + '/');
3req.setMethod('GET');1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/sobjects/
2MetadataContainer/ + containerID + '/');
3req.setBody('{"Name":"NewlyNamedContainer"}');
4req.setMethod('PATCH');1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/query/?q=
2Select+id,Name+from+MetadataContainer+Where+ID=\'' + containerID + '\'');
3req.setMethod('GET');1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/query/?q=
2Select+id,Body,LastSyncDate,Metadata+from+ApexClassMember+Where+MetadataContainerID=\'
3+ containerID + '\'');
4req.setMethod('GET');1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/sobjects/
2ContainerAsyncRequest/' + requestID + '/');
3req.setMethod('GET');To execute anonymous Apex:
1req.setEndpoint('http://na1.salesforce.com/services/data/v28.0/tooling/executeAnonymous/?
2anonymousBody=System.debug('Test')%3B');
3req.setMethod('GET');To retrieve your Apex classes and triggers, and the global Apex classes and triggers from your installed managed packages:
1req.setEndpoint('http://na1.salesforce.com/services/data/v33.0/tooling/apexManifest');
2req.setMethod('GET');