Search code examples
salesforceapexsoql

CompileClassResult Invalid Type


I'm developing some logic to compile all my classes and triggers in my org automatically every day. I found the following documentation to do it but when I tried running a simple command in the Execute Anonymous Window, I got the error below. Does anyone know why I'm having this error and how to get this working?

  • Production
  • Sandbox Class Trigger
  • ApexClass Class

    // Fails on this line with the error image below
    List<CompileClassResult> r = new List<CompileClassResult>();
    
    // Get a single Class to test with
    ApexClass tempClass = ([SELECT Body FROM ApexClass LIMIT 1]);
    
    // Example code from the Sandbox Class documentation
    try {
        r = apexBinding.compileClasses(new String[]{tempClass.Body});
    } catch (RemoteException e) {
        System.out.println('An unexpected error occurred: ' + e.getMessage());
    }
    
    // Show Results
    for(CompileClassResult tempResult : r)
    {
        if (!tempResult.isSuccess()) {
            System.out.println('Couldnt compile class p1 because: ' + tempResult.getProblem());
        }   
    }
    

enter image description here


Solution

  • These methods and objects are part of SOAP API and are not available from native apex. Hence you are seeing the error. You can move your logic to Java application as illustrated in the example in the documentation. The snippet you have pasted is Java code.:)

    For more info on Getting started with SOAP API https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_steps.htm