0

I imported the Tooling API WSDL back into Apex as toolingSoapSforceCom and added a Remote Site setting from my Salesforce pod/domain.

toolingSoapSforceCom.SforceService toolingService = new toolingSoapSforceCom.SforceService();
toolingService.SessionHeader = new toolingSoapSforceCom.SessionHeader_element();
toolingService.SessionHeader.SessionId = UserInfo.getSessionId();
toolingService.DebuggingHeader = new toolingSoapSforceCom.DebuggingHeader_element();
toolingService.DebuggingHeader.debugLevel = 'DEBUGONLY';
toolingService.DebuggingHeader.categories = new List< toolingSoapSforceCom.LogInfo>();
toolingSoapSforceCom.LogInfo apexLogInfo = new toolingSoapSforceCom.LogInfo();
apexLogInfo.category='Apex_code';
apexLogInfo.level='FINEST';
toolingService.DebuggingHeader.categories.add(apexLogInfo);
toolingSoapSforceCom.ExecuteAnonymousResult executeResponse = toolingService.executeAnonymous('System.debug(\'hello World\');');
System.assert(executeResponse.compiled);
System.debug(toolingService.DebuggingInfo);

Error Message

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService faultcode=UNKNOWN_EXCEPTION faultactor=

0

You need to reset the endpoint before you can call the service. The WSDL, by default, points to https://login.salesforce.com/ or https://test.salesforce.com/, but once you have a Session ID, you are expected to hit your local endpoint. The following code should suffice:

toolingService.endpoint_x = new URL(
  Url.getSalesforceBaseUrl().getProtocol(),
  Url.getSalesforceBaseUrl().getHost(),
  '/services/Soap/T/41.0').toExternalForm();

Note that it's probably a lot easier to use the REST API if whatever you're trying to do is in the REST API.

  • it works fine, but at the end System.debug(toolingService.DebuggingInfo); lines throws the null value, could you please help me in this. – Rehan Nov 13 '17 at 8:59
  • @Rehan DebuggingInfo would indeed be null in your object. You need to later query the ApexLog object to get your debug information back. – sfdcfox Nov 13 '17 at 13:26
0

According to error message, it simply says Destination URL not reset. So basically, when you use login you will receive SessionId and URL.

That URL (destination) must be assigned as an URL.

  • How Can I Fix this – Rehan Nov 13 '17 at 6:36

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.