Compile and test your Apex in a single call.
CompileAndTestResult[] = compileAndTest(CompileAndTestRequest request);
Use this call to both compile and test the Apex you specify with a single call. Production organizations (not a Developer Edition or Sandbox Edition) must use this call instead of compileClasses() or compileTriggers().
This call supports the DebuggingHeader and the SessionHeader. For more information about the SOAP headers in the API, see the SOAP API Developer's Guide.
All specified tests must pass, otherwise data is not saved to the database. If this call is invoked in a production organization, the RunTestsRequest property of the CompileAndTestRequest is ignored, and all unit tests defined in the organization are run and must pass.
Note that the following example sets checkOnly to true so that this class is compiled and tested, but the classes are not saved to the database.
{ CompileAndTestRequest request; CompileAndTestResult result = null; String triggerBody = "trigger t1 on Account (before insert){ " + " for(Account a:Trigger.new){ " + " a.description = 't1_UPDATE';}" + "}"; String testClassBody = "@isTest private class TestT1{" + " // Test for the trigger" + " public static testmethod void test1(){" + " Account a = new Account(name='TEST');" + " insert(a);" + " a = [select id,description from Account where id=:a.id];" + " System.assert(a.description.contains('t1_UPDATE'));" + " }" + " // Test for the class" + " public static testmethod void test2(){" + " String s = C1.method1();" + " System.assert(s=='HELLO');" + " }" + "}"; String classBody = "public class C1{" + " public static String s ='HELLO';" + " public static String method1(){" + " return(s);" + " }" + "}"; request = new CompileAndTestRequest(); request.setClasses(new String[]{classBody, testClassBody}); request.setTriggers(new String[]{triggerBody}); request.setCheckOnly(true); try { result = apexBinding.compileAndTest(request); } catch (RemoteException e) { System.out.println("An unexpected error occurred: " + e.getMessage()); } assert (result.isSuccess()); }
Name | Type | Description |
---|---|---|
request | CompileAndTestRequest | A request that includes the Apex and the values for any fields that need to be set for this request. |