+ Start a Discussion

{!$API.session_ID} w/ AJAX Toolkit gets Invalid Session Error

I thought this error was a thing of the past when Salesforce put out a fix for resolving Visualforce session Ids several years ago but it's apparently hard to kill.  Here are the facts:


The error is happening when using the session Id from the global API variable with the AJAX toolkit (see code below)

The Visualforce Page in question is part of a managed package

The customer hitting the error is doing so in a sandbox, Unlimited Edition

This app is working correctly for hundreds of other customers without a problem

The "lock session to originating IP" setting is turned OFF

Viewing Source on page confirms that a session Id is being populated on this line of the JS


For whatever reason this customer is getting "Invalid Session Id".  I could begin the "shots in the dark" and try going back to old school tactics like getting the session Id from the Apex controller instead of a merge field... but why is it working for all other customers and not this one?  Also, I don't want to do too much trial and error because its a huge PITA to uninstall in their sandbox, reupload a beta package, an reinstall for every little thing I want to try and test.


Any ideas?


<script src="../../soap/ajax/24.0/connection.js" type="text/javascript"></script>

<script type="text/javascript">
        sforce.connection.sessionId = '{!$Api.Session_ID}';




I still have no idea what the actual issue was, or where the erroneous session Id was coming from (or why it was invalid)... but I did stumble upon a fix:


There was a sidebar component from another app that, when removed, allowed my app to work.  Anyone else run into apps conflicting?  Perhaps both trying to load the AJAX toolkit?