Skip to main content
added 1020 characters in body
Source Link
Daniel Ballinger
  • 103k
  • 40
  • 275
  • 601

If you have located a global Apex class within the managed package with the required global method and you are working via the SOAP API then anonymous Apex would be a good option.

Using the executeAnonymous method in either the Tooling or Apex APIsApex APIs you can invoke the global method.

You call the method with a string containing the Apex to execute the method.

E.g. using some rough C#. You will need to replace PackageNamespace and PackageClass as required. The developer console would be a good place to test out the anonymous Apex first before writing the code against the SOAP API.

string anonApex = @"
    PackageNamespace.PackageClass pc = new PackageNamespace.PackageClass();
    PageReference pr = pc.allocate();
    System.debug(LoggingLevel.Error, pr);";

ToolingService toolingService = // create an instance of the ToolingService ...
ExecuteAnonymousResult result = toolingService.executeAnonymous(anonApex);

The trick will be if you want to extract some data from the resulting PageReference. There are two approaches I know of. Subvert an exception to return the required data or capture and process the resulting Apex Debug log.

If you have located a global Apex class within the managed package with the required global method and you are working via the SOAP API then anonymous Apex would be a good option.

Using the executeAnonymous method in either the Tooling or Apex APIs you can invoke the global method.

You call the method with a string containing the Apex to execute the method.

If you have located a global Apex class within the managed package with the required global method and you are working via the SOAP API then anonymous Apex would be a good option.

Using the executeAnonymous method in either the Tooling or Apex APIs you can invoke the global method.

You call the method with a string containing the Apex to execute the method.

E.g. using some rough C#. You will need to replace PackageNamespace and PackageClass as required. The developer console would be a good place to test out the anonymous Apex first before writing the code against the SOAP API.

string anonApex = @"
    PackageNamespace.PackageClass pc = new PackageNamespace.PackageClass();
    PageReference pr = pc.allocate();
    System.debug(LoggingLevel.Error, pr);";

ToolingService toolingService = // create an instance of the ToolingService ...
ExecuteAnonymousResult result = toolingService.executeAnonymous(anonApex);

The trick will be if you want to extract some data from the resulting PageReference. There are two approaches I know of. Subvert an exception to return the required data or capture and process the resulting Apex Debug log.

Source Link
Daniel Ballinger
  • 103k
  • 40
  • 275
  • 601

If you have located a global Apex class within the managed package with the required global method and you are working via the SOAP API then anonymous Apex would be a good option.

Using the executeAnonymous method in either the Tooling or Apex APIs you can invoke the global method.

You call the method with a string containing the Apex to execute the method.