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
rajarakrajarak 

Session_ID error in Visualforce page with AJAX toolkit

 

<apex:includeScript value="/soap/ajax/15.0/connection.js"/><apex:includeScript value="/soap/ajax/15.0/apex.js"/>sforce.connection.sessionId = '{!$Api.Session_ID}';

I have the above code in a visualforce page.

As per document, the AJAX toolkit supposed to handle the session Id by itself with no extra work.

But i get invalid sessionID error, if i dont set it onload of the page.

 

Is there something i'm missing?

Is using Controller the alternative to avoid this?

 

Thanks

KK 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
rajarakrajarak

Thanks Venkat,

 

But my question was, Shldn't the toolkit by itself handle the session id.?

If i set the session Id on load of the page it works fine. 

 

I was thinking that I missed something and thats why i had to explicitly set.

Or is this the way, session id needs to be handled in VF page? 

sforce.connection.sessionId = '{!$Api.Session_ID}';
 

All Answers

Venkat PolisettVenkat Polisett

Look at the following thread:

 

 

Session_ID in AJAX

rajarakrajarak

Thanks Venkat,

 

But my question was, Shldn't the toolkit by itself handle the session id.?

If i set the session Id on load of the page it works fine. 

 

I was thinking that I missed something and thats why i had to explicitly set.

Or is this the way, session id needs to be handled in VF page? 

sforce.connection.sessionId = '{!$Api.Session_ID}';
 
This was selected as the best answer
wintamutewintamute

Hi,

 

see following thread for a possible solution with invalid session IDs

Ezio_2010Ezio_2010

Mister, r u trying with custom controller or standar ?

 

i cant make it work with custom controller...really nasty!!!