3

Is there a way to call sforce.interaction.runApex or executeanonymous from the SOAP enterprise API?

I have a manged package that has an APEX method on it that I need to run from Java. The SOAP proxy doesn't seem to have an equivalent of either of these functions.

5

While the Enterprise WSDL doesn't expose it there are two other SOAP based APIs that will directly allow you to invoke executeanonymous from an external system.

The preferred and current method is via the Tooling API executeanonymous(string apexcode) method. There are both SOAP and REST based versions of this API.

The older version is in the Apex API executeanonymous().

Both the Tooling and the Apex SOAP API WSDLs are independent of the Enterprise WSDL and will need to be downloaded separately.

I've got an example of the raw SOAP request to execute anonymous in Adding Eval() support to Apex


The alternative, as Toby answered, is to create the web service direction in Apex and then export the WSDL from that class in the org with the managed package installed.

| improve this answer | |
  • is there an example of how to configure the tooling proxy from an enterprise connection? i know the metadata api was using the login result metadataServerUrl and the same session id. i'm hoping for something similar. – Daniel A. White Mar 24 '17 at 13:51
  • @DanielA.White You can use your same Session ID with both APIs. In terms of ServerURL, they only vary by a single letter. See What is the URL for using the Tooling API via SOAP?. The Enterprise API my have an additional versioning suffix that can be omitted. – Daniel Ballinger Mar 24 '17 at 19:42
3

I don't believe those exist but what you're trying to accomplish can be done using a WebService Method.

A developer of an external application can integrate with an Apex class containing webService methods by generating a WSDL for the class. To generate a WSDL from an Apex class detail page:

  1. In the application from Setup, enter “Apex Classes” in the Quick Find box, then select Apex Classes.
  2. Click the name of a class that contains webService methods.
  3. Click Generate WSDL.

That will allow your Java application to call the method directly.

If you're managed package doesn't have a pre-made webservice method, you can create one yourself artificially:

global class MyWebService {
    webService static void CallManagedPackage() {
        ManagedPackageClassName.MethodName();
    }
}
| improve this answer | |
  • my managed package doesn't have that... :( – Daniel A. White Mar 21 '17 at 19:09
  • @DanielA.White Updated Answer – gNerb Mar 21 '17 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.