In order to obtain a SessionID with maximal privileges I try to call login() via the API. I need that in order to ExecuteAnonymous with verbose Debug Log - see this post for Backgrounds: Get a FIRST-CLASS SessionID for API Calls (looking for a clean way or alternative)

At the question above @Eric suggested to use login() of the partner SOAP API in order to obtain a more powerful first-class SessionID with maximal privileges. I found that login() is supported by the JavaScript AJAX Toolkit. For just a test, it seems to be much easier using sforce.connection.login() then working with the WSDL.

What I did is very easy to reproduce: Having connection.js and apex.js already loaded, I simply went to a javascript console (firebug in my case) and entered


Using proper username, password and token of course. It immediately produces a nice callout:

<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/">
  <se:Header xmlns:sfns="urn:partner.soap.sforce.com">
    <login xmlns="urn:partner.soap.sforce.com" xmlns:ns1="sobject.partner.soap.sforce.com">

send to the endpoint https://elfcodefusion.eu0.visual.force.com/services/Soap/u/29.0

But the response ends with an error:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <faultstring>UNKNOWN_EXCEPTION: An unexpected error occurred. Please include this ErrorId if you contact support: 702236781-42797 (-188291932)</faultstring>
                <sf:UnexpectedErrorFault xsi:type="sf:UnexpectedErrorFault">
                    <sf:exceptionMessage>An unexpected error occurred. Please include this ErrorId if you contact support: 702236781-42797 (-188291932)</sf:exceptionMessage>



works like a charm.

Any idea what's wrong with my callout?


I found it!

The problem was the presence of the debug headers, possibly also the already active (low power) sessionId. Removing both, it works great! In my case I just unset the properties in JavaScript just like so:

sforce.connection.sessionId = null;
sforce.connection.debuggingHeader = null; // this, too is necessary!

Then call again


which produces a simpler XML and actually works :-)

<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/">
   <se:Header xmlns:sfns="urn:partner.soap.sforce.com"></se:Header>
      <login xmlns="urn:partner.soap.sforce.com" xmlns:ns1="sobject.partner.soap.sforce.com">

Hope this will help someone!

| improve this answer | |

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.