QUESTION:
We are using a custom Visualforce page to insert Accounts and have an Account Scenario set to "Do Not Insert" with the "Bypass Block" option selected. The insert is blocked but we also get a pop-up message regarding an INVALID_SESSION_ID which does not allow us to select the "Bypass Block" button in the blocking message. How can I resolve?
Example Error:
{faultcode:'sf:INVALID_SESSION_ID',
faultstring:'INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session',}
ANSWER:
This error happens occasionally when the Visualforce page is updated via AJAX rather than the standard full page refresh. To resolve add the following 3 lines of code to the top of the Visualforce page just after the opening <apex:page> tag.
<script type="text/javascript">__sfdcSessionId = '{!$Api.Session_Id}';</script>
<apex:includeScript value="/soap/ajax/31.0/connection.js" />
<apex:includeScript value="/soap/ajax/31.0/apex.js" />
Note: This example is for inserting accounts, but can happen inserting/updating any object via a custom Visualforce page that uses AJAX. It can also happen with blocking scenarios that do not have "Bypass Block" selected.