How to find Salesforce Permission Label with API Name?

How to find Salesforce Permission Label with API Name?

To find Salesforce Permission Label when we have API Name, we can make use of Schema.DescribeSObjectResult and Schema.DescribeFieldResult on PermissionSet object/entity.

Using the following code, we are finding the Label value of the PermissionsManageConvMiningReports Permission.

Sample Apex Code:

Schema.DescribeSObjectResult objectDescribeResult = 
    PermissionSet.sObjectType.getDescribe();  
Map < String , Schema.SObjectField > mapFieldList = 
    objectDescribeResult.fields.getMap();    

for ( 
    Schema.SObjectField field : 
    mapFieldList.values() 
) {    
  
    Schema.DescribeFieldResult fieldResult = 
        field.getDescribe(); 

    if ( 
        fieldResult.getName() == 'PermissionsManageConvMiningReports' 
    ) {

        System.debug(
            'Field Label is ' + 
            fieldResult.getLabel()
        );
        break;

    }
      
}

Leave a Reply