Posts

Showing posts with the label permissionset

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 #890 | Unassign a PS from all PSGs

Image
Suppose we have a PS which is assigned to multiple PSGs. Now, for some reason we would like to unassign it from all the PSGs. The attached apex code snippet would be helpful for the same:

Salesforce Fact #875 | Checking custom metadata access in PS

Suppose we need to find out which all permission sets have a particular custom metadata access enabled. For this, first we need to find out the object Id of the custom metadata and using that object id we can get the list of permission sets. In this example, first we are getting the object id of the custom metadata. This can be obtained either from the url or by querying the CustomObject as below: SELECT Id FROM CustomObject WHERE DeveloperName='Parent_Metadata' Next, we query on SetupEntityAccess like below: SELECT Id, Parent.name, SetupEntityId, SetupEntityType, SystemModstamp FROM SetupEntityAccess WHERE parent.isownedbyprofile=False AND SetupEntityId IN ('01I6F000003cdLBUAY')

Salesforce Fact #709 | Assign PermissionSet in TestSetup()

Image
Suppose we need to test scenarios across multiple test methods in the context of a particular user and also a PS needs to be assigned to the user in order to gain access to required records. This is how we can create the user and assign the PS in TestSetup() method and in each test method we can fetch the user and use System.runAs(). Attached are the screenshots.

Salesforce Fact #654 | Custom permission assignments

Image
Suppose we have a scenario where we need to find out a particular custom permission is assigned to which all permission sets. There is an object called SetupEntityAccess which is helpful in this case to get the details. In this example, we are getting the details for a custom permission named ' Test_Custom_Permission'. SOQL used ->  SELECT Id, Parent.name, SetupEntityId, SetupEntityType, SystemModstamp FROM SetupEntityAccess  WHERE parent.isownedbyprofile=False AND SetupEntityId IN (SELECT Id FROM CustomPermission  WHERE DeveloperName='Test_Custom_Permission') Attached is the screenshot.

Salesforce Fact #548 | Permset assignment to inactive user

If we try to assign any permission set to any inactive user by mistake, we get the below error: INACTIVE_OWNER_OR_USER, owner or user is inactive. Org Id:<orgid> However, we can remove permission sets from inactive users.