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();
toolingSoapSforceCom.ExecuteAnonymousResult executeResponse = toolingService.executeAnonymous('System.debug(\'hello World\');');

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=

2 Answers 2


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(

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
    Commented Nov 13, 2017 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
    Commented Nov 13, 2017 at 13:26

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
    Commented Nov 13, 2017 at 6:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .