RunTest with Salesforce Tooling REST API (asynchronous and synchronous)

Salesforce supports running test with Tooling REST API ,which are runTestsAsynchronous and runTestsSynchronous.

In this post I’ll show you what is the difference between runTestsAsynchronous and runTestsSynchronous.


1.Salesforce Account
2.apigee for Salesforce (
3.A TestClass (Id=01p10000001Faws) such as:


Running tests asynchronously allows methods to process in parallel, cutting down your test run times.
(In fact,it is really slow, even will cost you more than 10 mins :()

First,we need to login apigee with Salesforce OAuth2.
apigee apigee-auth2 REST API Version after V28.0 supports Tooling API,so change the endpoint from [] to [].
Set Request URL and Parameter like the following capture then send request. apigee-runTestsAsynchronous


As we see,the request will return an object Id,actually,it is an AsyncApexJob Id.
And we will find that a Test has been run at “Apex Test Execution”. Apex Test Execution Then how do we get the details of this Test Result?
Use Tooling API we can also Query the details from related sObjects. Here is the sObjects ER. ER

1.ApexTestQueueItem [Document]



2.ApexTestResult [Document]


3.ApexCodeCoverage [Document]



As the word, runTestsSynchronous will execute Apex tests synchronously so we can get the Test Result directly.
Set Request URL and Parameter like the following capture. apigee-runTestsSynchronous


And test will not run at “Apex Test Execution” in this way. Apex Test Execution-runTestsSynchronous That is why running test with Sublime Text3 + MavensMate is always faster than running with Salesforce Developer Console,I suppose.

Related Post

Usages of ID class in Salesforce As we know that each record Id represents a unique sObject record. There are two versions of every record Id in salesforce : ・15 digit case-sensitive version which is referenced in the UI ・18 digit case-insensitive version which is referenced through the API And there are many usages of sObject I...
Salesforce Dev Tools for Chrome™ Salesforce Dev Tools for Chrome™ is a Chrome extension helping developers do the below things: ・Export definition of objects to Excel file. ・Show / Hide object API name on object detail page by 1 Click. ・Quick generate test data Apex Code for Unit Test. ・Quick access to new...
Salesforce Apex Zip Attachments With JSZip Sometimes we need to zip Attachments or PDFs and download it at once in Salesforce development. As we know, Apex does not support Zip. it is conceivable that Zip files with other service such as Heroku or AWS, But in fact we can do this without any External Service, just Salesforce and JavaScript....
A bug caused by Decimal without SetScale Let's see the following Apex Script first. In fact the Apex Script will throw an AssertException. "System.AssertException: Assertion Failed: Expected: 0E-32%, Actual: 0%". So we'd better round the Decimal before we convert it to String.Like the ...