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
Kundan PathakKundan Pathak 

How to get sessionid in visualforce page which I am using in Salesforce Site

I have written a code to attach multiple attachment from vf page using forcetk.
The code is working fine when I am running the VF page individually
but when I am attaching the VF page in Salesforce Site the file is not attaching and its giving INVALID_SESSION_ID.

Is there any way to get SessionID in Salesfore Site.
Can anyone help..??
Khan AnasKhan Anas (Salesforce Developers) 
Hi Kundan,

Greetings to you!

According to Salesforce Knowledge Article (https://help.salesforce.com/articleView?id=000204984&type=1):

Before Winter 15, it was possible to get the session id for the guest user. Now, an error code saying "INVALID_SESSION_ID" is returned if you try to get the session ID of the guest user.

This change ensures that you can still create a guest user session, but doesn't allow a guest session ID to be set or created for organization security.

There are no recommended workarounds. Affected customers will need to adjust their integration to not rely on a guest user session ID.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Priyananth RPriyananth R
Hii,
try this js code,
var __sfdcSessionId = '{!GETSESSIONID()}';
Shaik Naga janiShaik Naga jani
Hi Kundan,
Include this statement in your VF page, this will fetch the session Id based on your Org.
<script type="text/javascript">sforce.connection.sessionId = "{!$Api.Session_ID}";</script>
it automatically gets the session id, I am using my page in sites also it working as excepted.
Kindly mark this as solved if the reply was helpful.
Thanks
Shaik
narsavagepnarsavagep

For my purposes, I was able to use "BrowserId" cookie - which appears to be unique for each time the browser session is started.

let sessionId = /BrowserId=([^;]+)/i.test(document.cookie) ? RegExp.$1 : 'unknown';