You need to sign in to do that
Don't have an account?
Rogerio Da Silva
Get Session ID/Token in Lightning Component for Communities
Hi There,
We have a custom component in my Community Page and we are trying to get the Session Id or Access Token from the user who is logged in on Community Builder using Preview mode.
We have a code in place that works if the user is not in Preview Mode, basically we call an apex code and execute the UserInfo.getSessionId(), it returns the sessionid and I can do a rest call with this session ID.
This SessionID works just when the user publishes a page and access it using the public URL. When I get the SessionID inside of Community Builder and click on Preview, and try to do a rest call with the session ID, it gives me an Invalid Session.
The link below is the link that I access my page and I can get the SessionId and do a rest call with no issue.
https://xxxdeveloper-edition.na50.force.com/CMSite/s/
The link below is when I am on Community Builder - Preview Mode, in this case I get the SessionID, but I cannot do a REST call.
https://xxxdev-ed--sitepreview.na50.force.com/CMSite/s/
said all that I have two questions.
1 - Why this Session Id in Preview mode is invalid, but the same code when I am using public link it works just fine?
2 - Is there another way to obtain the SessionId where I can do a Rest Call using Lightning component in Community Builder?
Please, let me know if you need any further information.
Thank you in advance.
We have a custom component in my Community Page and we are trying to get the Session Id or Access Token from the user who is logged in on Community Builder using Preview mode.
We have a code in place that works if the user is not in Preview Mode, basically we call an apex code and execute the UserInfo.getSessionId(), it returns the sessionid and I can do a rest call with this session ID.
This SessionID works just when the user publishes a page and access it using the public URL. When I get the SessionID inside of Community Builder and click on Preview, and try to do a rest call with the session ID, it gives me an Invalid Session.
The link below is the link that I access my page and I can get the SessionId and do a rest call with no issue.
https://xxxdeveloper-edition.na50.force.com/CMSite/s/
The link below is when I am on Community Builder - Preview Mode, in this case I get the SessionID, but I cannot do a REST call.
https://xxxdev-ed--sitepreview.na50.force.com/CMSite/s/
said all that I have two questions.
1 - Why this Session Id in Preview mode is invalid, but the same code when I am using public link it works just fine?
2 - Is there another way to obtain the SessionId where I can do a Rest Call using Lightning component in Community Builder?
Please, let me know if you need any further information.
Thank you in advance.
1.- The session is related with the domain. Because of this the session is invalid in preview
2.- The best option is to get access token again. You can see how here(https://spaindevelop.wordpress.com/2017/08/05/usando-salesforce-tooling-api-salesforce-rest-api/) (sorry but is Spanish)
Hope this helps.
Please mark this as solved if it's resolved.
Thanks,
Nagendra
Here are the two domains that I tested.
https://xxx-dev-ed.my.salesforce.com
https://xxx-developer-edition.na50.force.com/sfsites/c