Posts

Showing posts with the label SessionId

Salesforce Fact #907 | Session based PS in Apex

Image
The object SessionPermSetActivation stores the active Session based PS assignments. We can insert data in this object from apex as well. If you encounter the error 'Field is not writeable: SessionPermSetActivation.AuthSessionId' then you need to enable the system permission: 'Manage Session Permission Set Activation' for the user. Reference:  https://salesforce.stackexchange.com/questions/310240/sessionpermsetactivation-doesnt-work-according-to-specification Attached is one sample code snippet.

Salesforce Fact #667 | Get current session Id

If we use System.debug() to get the current session Id, it shows SESSION_ID_REMOVED.  So, in order to get the SessionId we can use a bit of apex logic as below: System.debug(UserInfo.getOrganizationId()+''+UserInfo.getSessionId().substring(15)); Note: The first 15 char of session Id is the Organization Id. Reference:  https://developer.salesforce.com/forums/?id=9062I000000g6v7QAA