1

Is there any chance to add Apex Class Access to a permission set programmatically? E.g. the following code allows adding field permissions to the perm set.

insert new FieldPermissions(
        ParentId = '0PSXXXXXXXXXXXX', // perm set id
        SobjectType = SObjectType.Account.getName(), 
        Field = Account.Type.getDescribe().getName(),
        PermissionsRead = true,
        PermissionsEdit = false,  
);

Does anyone know how to do the same with Apex Classes?

1 Answer 1

4

Yes, it is possible to be done in the same way as with FieldPermissions, but you need to use SetupEntityAccess object instead:

insert new SetupEntityAccess(
        ParentId = '0PS...', // PermissionSet ID
        SetupEntityId = '01p...' // ApexClass ID
);
1
  • Works great, thanks!
    – DrWebber
    Commented Oct 29, 2021 at 11:22

You must log in to answer this question.

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