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

Salesforce Mass Editor (Chrome Extension) – ... This's my second Chrome Extension (First one is HERE) this year, named "Salesforce Mass Editor" and it supports for doing the below things : ・Makes any Salesforce list view to be a powerful mass editor. ・Mass insert, mass clone, mass update, mass delete, ALL-IN-ONE. ・Export record data to CSV fi...
Setup an awesome Salesforce developer environment ... Why Sublime Text 3 ? I've been working with for about 2 years, and always using IDE(See here, Eclipse IDE Installation)as my development environment. I don't think it is difficult to use, but it could more friendly. For example: 1. It doesn't support APEX an...
Instantiating an Apex class based on dynamic strin... Somtimes we need to instantiate a Apex class by dynamic value in Salesforce, which can make our program more modular and more readable, such as the below case : 1. Each Contact has its socail fields : "Type__c" and "AccessToken__c" 2. Needs to request its profile via socail api in Apex Firs...
Using Aggregate SOQL queries/results in Batch Apex In previous post, we had created a schedulable batch apex that implements Database.Batchable in Salesforce, but if you want to use SOQL having aggregate functions like SUM(), MAX(), COUNT() on results grouped by “GROUP BY” clause in start execution, changing to interface Database.Ba...