5

I'm trying to check the User assigned Custom Permission from a Managed Package. The Custom Permission and the Permission Set are not part of the package, but in the subscribers Org.

Currently I'm trying to use the FeatureManagement.checkPermission(), but seems that the package can't access to the Custom Permission record. The call inside the package returns False, when instead made from out of package (execute anonymous) the return value is True.

To be clearer, an example of code I'm running:

//execute anonymous
System.debug(NS.MyClass.customPermissionMethod('myCustomPermission')); //return false
System.debug(FeatureManagement.checkPermission('myCustomPermission')); //return true


//Managed Package Class    
global class MyClass {
    global static boolean customPermissionMethod(value) {
        return FeatureManagement.checkPermission(value);
    }
}

I have not found anything on the documentation that spoke of this specific case, has it ever happened to you?

9
  • 1
    I think that sounds right Andrea, because FeatureManagement seems to be built to check Custom Permission owned by a given Managed Package: developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/… Commented Nov 27, 2019 at 10:50
  • Thanks Jeferson! It will be the case, however, there is no reference to the package in the "FeatureManagement Class" documentation link. The methods performed outside the package work without particular constraints
    – Andrea P.
    Commented Nov 27, 2019 at 13:33
  • Yes, you are correct as well Andrea, I think it might be worth to open a case then. Commented Nov 27, 2019 at 14:20
  • Yes, we'll contact the SF Support!
    – Andrea P.
    Commented Nov 28, 2019 at 8:42
  • 1
    Did you try querying the permissions table instead? Like in this answer: salesforce.stackexchange.com/a/138563/18269 Also: the answer for this question here is four years old now, so you might want to open a new question and reference this one within it instead. Commented Jun 27 at 16:35

2 Answers 2

6

Salesforce support told us that this is an error in the documentation, which they will correct. The "checkPermission" method inside a managed package will only be able to verify the custom permissions of the package itself. To get around this, you need to implement the "workaround" solution with 2 queries.

I don't fully agree with this choice/answer, but that's it.

1
  • There is still no note in the documentation about this but it still seems to be the case. Querying seems to be the only option. If you need to check multiple permissions, I found a static, one time get of all user customer permissions in a set limits this to 2 queries always Commented Jul 3 at 16:41
1
+50

Another solution to this limitation of the platform would be to query the permission table with SOQL, as in this question. You can query the SetupEntityAccess table or, more directly, the PermissionSet table alongside the PermissionSetAssignment (to check which permission set was assigned to which user).

You must log in to answer this question.

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