function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hlottehlotte 

'Invalid Session ID found in SessionHeader' on sforce.apex.execute

Hi,

 

I'm trying to do a AJAX call with this class:

global class NetsizeTest { WebService static String Test(/*String contactId*/) { return 'Test'; } }

 

 and this APEX page :

<apex:page standardController="SMS__c" extensions="NetsizeClass">
<apex:sectionHeader title="New SMS" subtitle=""/>
<apex:includeScript value="/soap/ajax/16.0/connection.js"/>
<apex:includeScript value="/soap/ajax/16.0/apex.js"/>
<script>
function getMobileNumber(input)
{
sforce.debug.trace = true;
var c_id = document.all[input.id + '_lkid'].value;
try
{
var mobilePhone = sforce.apex.execute('NetsizeTest','Test',{/*contactId:c_id*/});
alert (mobilePhone);
} catch(e)
{
alert(e.faultCode?e.faultCode:e.message?e.message:e)
}

}
</script>

<apex:form >
<apex:pageBlock title="SMS information">
<TABLE>
<TR>
<TD><B>Contact</B></TD>
<TD><apex:inputField id="smsContact" value="{!sms.Contact__c}" onselect="javascript:getMobileNumber(this)"/></TD>
</TR>
<TR>
<TD><B>Mobile phone</B></TD>
<TD><apex:inputField id="smsMobilePhone" value="{!sms.MobilePhone__c}"/></TD>
</TR>
</TABLE>
<br/>
<apex:message for="smsContact" styleClass="" /> <p />
</apex:pageBlock>

</apex:form>
</apex:page>

 but when I do the call (without the try/catch in JS), I receive a Javascript error

Message: Exception thrown and not caught
Line: 1019
Char: 13
Code: 0
URI: https://c.cs2.visual.force.com/soap/ajax/16.0/connection.js

 

When I catch the error, I get this exception:

{faultcode:'sf:INVALID_SESSION_ID', faultstring:'INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session', }

 

I get the same error with or without the parameters ContactId.

 

I get this information too, from the AJAX call debug

Request: server- /services/Soap/package/NetsizeTest

<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"><se:Header xmlns:sfns="http://soap.sforce.com/schemas/package/NetsizeTest"/><se:Body><Test xmlns="http://soap.sforce.com/schemas/package/NetsizeTest"/></se:Body></se:Envelope>

 

Response : status - 500

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="http://soap.sforce.com/schemas/package/NetsizeTest"><soapenv:Body><soapenv:Fault><faultcode>sf:INVALID_SESSION_ID</faultcode><faultstring>INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>

 

 

I checked the session settings : timout is 4h, 'Lock sessions to the IP ...' is unchecked.

 

I don't see any mentions to a session in the doc or examples I found

Am I missing something ?

 

Thanks in advance for your help

Hervé

 

 

hlottehlotte
For information, I managed to bypass my problem by using an <apex:actionFunction> (that I just discovered :)), that works much better for what I want to do (retreive the mobile phone of a selected contact)
ChellappaChellappa

Hi hlotte,

 

Could u plz explaing how to overcame this problem with apex:actionFunction(). I am also facing the same problem.

THanks in advance for the help

 

Regards,

Chellappa

hlottehlotte

Hi Chellappa,

 

you defined the method you want to call as a classic method in your class, not a webservice.

Then you link this method to your APEX page by using an ActionFunction. With this, you'll be able to call your method with a javascript command.

 

The method to call (that will retreive the data in SalesForce) :

global class NetsizeTest { public void String GetMobileNumberFromContact() { // Retreive the data with myCpnt.Contact__c myCpnt.MobilePhone__c = 'Test'; } }

 

Then, in my APEX page, I used this:

 

<apex:form id="cpntForm"> <apex:actionFunction action="{!GetMobileNumberFromContact}" name="GetMobileNumberFromContact" reRender="MobilePhone" status="getMobilePhoneStatus" />

 

<apex:pageBlock title="Details">
<apex:pageblocksection title="Information" id="infoEditPanel">

 

<apex:inputField id="Contact" value="{!myCpnt.Contact__c}" onblur="if (this.value != '') GetMobileNumberFromContact();"/>

 

<apex:pageblockSectionItem >
<apex:outputLabel value="Mobile Phone(*)" />
<apex:panelGroup >
<apex:inputtext id="MobilePhone" value="{!myCpnt.MobilePhone__c}" />
<apex:actionStatus startText=" searching..." id="getMobilePhoneStatus"/>
</apex:panelGroup>
</apex:pageblockSectionItem>
 


</apex:pageblocksection>

  </apex:pageBlock>
</apex:form>

 Hope it will help you

Hervé

 

 

B01000111B01000111

connection has init method you need change the host and SessionId sforce.Connection.init('URL', 'SESSIONID')