Newer Version Available
SessionPermSetActivation
The SessionPermSetActivation object represents a
permission set assignment activated during an individual user session. When a SessionPermSetActivation object is inserted into a
permission set, an activation event fires, allowing the permission settings to apply to the
user’s specific session. This object is available in API versions 37.0 and
later.
Supported Calls
describeLayout(), describeSObjects(), query(), retrieve()
Special Access Rules
As of Summer ’20 and later, only users who have one of these permissions can access this object:
- View Setup and Configuration
- Manage Session Permission Set Activations
Fields
| Field Name | Details |
|---|---|
| AuthSessionId |
|
| Description |
|
| PermissionSetGroupId |
|
| PermissionSetId |
|
| UserId |
|
Usage
Use SessionPermSetActivation to create a permission set available only for a specified session’s duration. For example, create permission sets that provide access to specific applications only during authenticated sessions.
In the following Apex example, an identified session is activated after session information is submitted via a button. Successful activation results in a confirmation message displayed to the user.
1public class SessionPermSetActivationController {
2 // id of the session permission set to be activated
3 private final String sessionPermSetId = '0PSxx00000004rJ';
4 private final String sessionId;
5
6 public SessionPermSetActivationController() {
7 Map<String, String> sessionManagement = Auth.SessionManagement.getCurrentSession();
8 sessionId = sessionManagement.get('SessionId');
9 }
10
11 public PageReference activate() {
12 // activate the permission set
13 SessionPermSetActivation activation = new SessionPermSetActivation();
14 activation.AuthSessionId = sessionId;
15 activation.PermissionSetId = sessionPermSetId;
16 activation.Description = 'created by SessionPermSetActivationController';
17
18 insert activation;
19 return null;
20 }
21
22 public boolean getActivated() {
23 Integer alreadyActivated = [SELECT count()
24 FROM SessionPermSetActivation
25 WHERE AuthSessionId = :sessionId
26 And PermissionSetId = :sessionPermSetId LIMIT 1];
27 return alreadyActivated > 0;
28 }
29}
30
31
32<apex:page controller="SessionPermSetActivationController">
33 <apex:outputPanel rendered="{!!Activated}">
34 <h3>Activate Session Permission Set</h3>
35 <br />
36 <apex:form >
37 <apex:commandButton action="{!activate}" value="Activate" id="activateButton"/>
38 </apex:form>
39 </apex:outputPanel>
40 <apex:outputPanel rendered="{!Activated}">
41 <h3>Session Permission Set is already active.</h3>
42 </apex:outputPanel>
43</apex:page>