Newer Version Available

This content describes an older version of this product. View Latest

Using Tooling SOAP API

Use SOAP API if you’re using a strongly typed language like Java that generates Web service client code. Tooling SOAP API is used just like the Salesforce SOAP API. For details on usage, syntax, and authentication, see the SOAP API Developer's Guide.

To access the Tooling API WSDL, from Setup, click Develop | API and click Generate Tooling WSDL.

Like the Salesforce SOAP API, Tooling API uses the following calls.

Call Description
create() Adds one or more new records to your organization’s data.
delete() Deletes one or more records from your organization’s data.
describeGlobal() Lists the available Tooling API objects and their metadata.
describeSObjects() Describes metadata (field list and object properties) for the specified object or array of objects.

Call describeGlobal() to retrieve a list of all Tooling API objects for your organization, then iterate through the list and use describeSObjects() to obtain metadata about individual objects.

executeanonymous(string apexcode) Executes the specified block of Apex anonymously and returns the result.
query() Executes a query against a Tooling API object and returns data that matches the specified criteria.
retrieve() Retrieves one or more records based on the specified IDs.
runTests() and runTestsAsynchronous() Executes test methods in the specified classes. Running tests asynchronously allows methods to process in parallel, cutting down your test run times. For example code, see ApexTestQueueItem.
update() Updates one or more existing records in your organization’s data.
upsert() Creates new records and updates existing records; uses a custom field to determine the presence of existing records.

Examples

These examples use Java, but you can use Tooling SOAP API in any language that supports Web services.

Use create() to compile Apex classes or triggers in Developer Edition or sandbox organizations. The first example below uses ApexClass to compile a simple class with a single method called SayHello.

Use the IsCheckOnly parameter on ContainerAsyncRequest to indicate whether an asynchronous request should compile code without making any changes to the organization (true) or compile and save the code (false).

The example below expands upon the first by modifying the SayHello() method to accept a person’s first and last name. This example uses MetadataContainer with ApexClassMember to retrieve and update the class, and ContainerAsyncRequest to compile and deploy the changes to the server. You can use the same method with ApexTriggerMember, ApexComponentMember, and ApexPageMember.
To test your code, modify the IsCheckOnly parameter in the code below, and log in to your org after a successful execution to verify the results.
  • When IsCheckOnly = true, the SayHello() method should remain the same. (ApexClassMember contains the compiled results, but the class on the server remains the same.)
  • When IsCheckOnly = false, the SayHello() method should show the change to accept a person’s first and last name.

Note

Use a SymbolTable to access Apex class and trigger data in a structured format.

The example below queries the ApexClassMember object created in the previous example to obtain the SymbolTable of the modified class.

The SOQL statement used depends on when the data is retrieved.

  • To execute the query from within the example above, use the ID of the ContainerAsyncRequest. For example, SELECT Body, ContentEntityId, SymbolTable FROM ApexClassMember where MetadataContainerId = '" + requestId + "'"
  • Otherwise, use the ID of the modified class as shown below. For example, SELECT ContentEntityId, SymbolTable FROM ApexClassMember where ContentEntityId = '" + classId + "'"

Note

Use ApexExecutionOverlayAction to add checkpoints to your code for debugging.

This example adds a checkpoint to the class from the previous examples: