I have a visualforce page in which I have used Ajax tool kit for search functionality. Its working fine in Vf page. But when I rendered the page Using Sites Iam unable to get sessionId.

How can I get sessionId in Sites page without using any username and password.


There is no way to get session Id in visualforce if your visualforce page is hosted on force.com site. If you have controller then by creating getter you can initialize the session Id and refer it again in visualforce page.

In controller :

public string sessionId {get;private set;}

Initialize this in constructor :

sessionId  = UserInfo.getSessionId();

and refer in visualforce page :

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

hope this will work.

| improve this answer | |

The main use of using sites is to make pages publicly accessible.

A valid user session is not established unless user log's in to salesforce using any of the login mechanisms(SSO, Communities, salesforce login..,)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.