2

There is an issue with implemention of the following feature : https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_sessionpermsetactivations.htm

In attempt to utilize the described example :

public PageReference activate() {
        // activate the permission set
        SessionPermSetActivation activation = new SessionPermSetActivation();
        activation.AuthSessionId = sessionId;
        activation.PermissionSetId = sessionPermSetId;
        activation.Description = 'created by SessionPermSetActivationController';
    
        insert activation;
        return null;
    }

Received the error:

FIELD_INTEGRITY_EXCEPTION, Session permission set cannot be activated for a child session.: []

Is there any way to execute the above from APEX.

I have also found the way how to achieve that with Flows (https://abhinavswarup.wordpress.com/2017/10/13/session-based-permission-sets/), however would be great to know whether it could work directly from APEX.

Thanks

2 Answers 2

2

You need to check for the parent Session, and use that if available:

Map<String, String> sessionInfo = Auth.SessionManagement.getCurrentSession();
String parentSession = sessionInfo.get('ParentId'), sessionId = sessionInfo.get('SessionId');

activation.AuthSessionId = parentSession!=null?parentSessionId:sessionId;
1
0

I don't think this is the right answer. No matter what I try, I get "Field is not writable - AuthSessionId". And if you look at the reference, it doesn't allow Insert. So the example they show isn't accurate.

1
  • 1
    The answer is correct. You are possibly running into "Field is not writable" error because your might not have Manage Session Permission Set Activation permission assigned.
    – arut
    May 10, 2022 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .