+ Start a Discussion
john hejohn he 

the session binding on Visualforce page

Sorry, I a new people on Visualforce page development.

 

when I develop visualforce page, I am confusing by the session binding syntax.

 

in the "AJAX Tookit Developer's Guide" book, I find an example on page 6, it puts the following code on the VF page:

<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
</script>

 

I believe, the above code is used to do the session binding.

 

But on the other hand, I find some VF page are use the following code to do the session binding:

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

 

what is the different between the first approach and the second one?  could someone help on this?  many thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Niket SFNiket SF

Hello John,

 

            A] var __sfdcSessionId = '{!GETSESSIONID()}'; In the first method you are using javascript to acess Session id whichgives the session id stored in the browser cookies.

 

           B]  "{!$Api.Session_ID}" when you are using this it means it gives you session id via Global variable.

 

     According to best practices we need to use Global variables

 

If it helps you please mark as a solved it will help others :)

All Answers

Niket SFNiket SF

Hello John,

 

            A] var __sfdcSessionId = '{!GETSESSIONID()}'; In the first method you are using javascript to acess Session id whichgives the session id stored in the browser cookies.

 

           B]  "{!$Api.Session_ID}" when you are using this it means it gives you session id via Global variable.

 

     According to best practices we need to use Global variables

 

If it helps you please mark as a solved it will help others :)

This was selected as the best answer
john hejohn he

thank you, Nik! 

RamsRams

Hi Niki,

 

I need to set the session setting for visualforce page. If the user login in to salesforce through vf page. After 1 hour i need to show the pop with some message. Please help me how to do this. Please help me out.

 

Thanks,

Rams