11

How to determine in APEX whether specific profile is custom or not?

There is a checkbox on a profile page that says "Custom Profile", but I couldn't find any field on the Profile object to be selected by a query. Is there a way to determine custom profiles using only APEX and SOQL?

2

3 Answers 3

14

Since this question was posted, a new field was added as of the Spring release API Version 39 - IsCustom - to the permissionSet object. Since the permissionset object is an amalgamation of the Profile and PermissionSets, you can simply use a query to accommodate this use case.

List<PermissionSet> profiles = new List<PermissionSet>([SELECT Id, Profile.Name
                                                        FROM PermissionSet
                                                        WHERE IsOwnedByProfile = true AND IsCustom = true]);

Please note that in the SOQL Query the permissionSet object has a field called "IsOwnedByProfile" to denote that the field is a permissionSet or a Profile and IsCustom denotes whether or not the profile is standard or custom.

Please also note that at the time of writing this post there is not a field called IsCustom on the profile object, except with the usage of the metadata API - denoted by the tag.

Spring '17 Release Notes Changed Object List (includes information about new IsCustom field)

2
  • there is a permission set that is owned for every profile, so this works great Nov 25, 2019 at 18:59
  • Is it documented somewhere that a permission set is owned for every profile ? Nov 13, 2023 at 17:15
9

Unfortunately there is no 'IsCustom' field or anything similar on the Profile object.

The only workaround that I know of is to compare the CreatedDate of your Profiles to the CreatedDate of you org.

Organization org  = [SELECT Id , CreatedDate FROM Organization]; 
List<Profile>  customProfiles = 
[
    SELECT Id, Name, CreatedDate 
    FROM Profile 
    WHERE CreatedDate > :org.CreatedDate
];

This is not a perfect solution as in one of my orgs this still bring back the 'Chatter Free User', 'Chatter Moderator User', 'Chatter External User' and 'Guest License User'. You can filter these values out, although I'm not sure if the below will work in non-English language orgs.

Organization org  = [SELECT Id , CreatedDate FROM Organization]; 
List<Profile>  customProfiles = 
[
    SELECT Id, Name, CreatedDate 
    FROM Profile 
    WHERE CreatedDate > :org.CreatedDate 
    AND Name NOT IN('Chatter Free User', 'Chatter Moderator User', 'Chatter External User', 'Guest License User')
];
0

Standard Profile Query:

SELECT Profile.Name FROM PermissionSet Where Iscustom=false AND ProfileId != null

Custom Profile Query:

SELECT Profile.Name FROM PermissionSet Where Iscustom=true AND ProfileId != null

You must log in to answer this question.

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