How to Get the Session Id of Current User in Lightning Context

The session id can be fetch through UserInfo.getSessionId() method in apex but which is not available lightning context. Named credentials and connected apps can be used to connect with external web services and internal salesforce api’s with Salesforce. This would requires more configurational effort and changes should be align with each deployments with respect to the orgs.

Here, I would like to share you a work around to solve this issue by using a custom visual force page and an apex controller.

String sessionId =  LexSessionController.fetchUserSessionId();

This expression {!$Api.Session_ID} provides the session id of the current user in the VF page, which is extracted in the apex controller. the below code snippet helps to get the session id in the lightning context (AuraEnabled methods).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s