Native Apex support for Custom Permissions - Ideas - Salesforce Trailblazer Community
Trailblazer Community

All Ideas

Idea Details

Post an Idea
3,670  Points
Idea has been posted. Give it an upvote or downvote.

Native Apex support for Custom Permissions

Development (Apex, LWC & VF)

Custom Permissions provide an excellent means to describe process or task based permissoins in our applications / packages. These can be assigned to Profiles or Permission Sets. An excellent feature! 

As a Visualforce developer its really easy to check if a user has a given Custom Permission via $Permission, however as a Apex developer this requires at least two SOQL queries. Much like how Custom Labels are available to both Visualforce ($Label) and Apex (System.Labels), this idea to suggest that Apex exposes Custom Permissions as a native entity within Apex to avoid impacting the SOQL query governor.

Apex: (idea being requested here) 

if(System.Permission.canSeeExecutiveData) {
Apex: (already available approach via SOQL, snippet from helper class described here)
List<CustomPermission> customPermissions =
    [SELECT Id, DeveloperName
       FROM CustomPermission
       WHERE NamespacePrefix = :namespacePrefix];
List<SetupEntityAccess> setupEntities =
    [SELECT SetupEntityId
       FROM SetupEntityAccess
       WHERE SetupEntityId in :customPermissionNamesById.keySet() AND
             ParentId IN (SELECT PermissionSetId
                FROM PermissionSetAssignment
                WHERE AssigneeId = :UserInfo.getUserId())];
Visualforce: (already available, shown for reference here)
<apex:pageBlock rendered="{!$Permission.canSeeExecutiveData}">

Merge Idea · Flag

Latest Comment from Salesforce

  • Belinda Wong - 2 years ago

    As noted in several comments, this was released in Winter '18 as part of the FeatureManagement Apex Class:


    Checks whether a custom permission is enabled.


    public static Boolean checkPermission(String apiName)


    Type: String
    The API name of the custom permission to check the value of—for example, 'MyCustomPermission'.
  • Upvotes
  • Downvotes



from AppExchange

Help us to keep IdeaExchange clean by pointing out overlapping ideas. We'll investigate your suggestion and merge the ideas if it makes sense.



Thanks for your merge suggestion. We will review it shortly and merge the ideas if applicable.

Salesforce takes abuse situations very seriously. Examples of abuse include but are not limited to posting of offensive language or fraudulent statements. To help us process your request as quickly as possible, please fill out the form below describing the situation. For privacy and security reasons, the final outcome of an abuse case may not be revealed to the person who reported it.


Thank you for your feedback. We take abuse seriously and will investigate this issue and take appropriate action.