14

Is it possible to know if a profile is custom via API?

Like an attribute "profile.isCustom".

9

The short answer is no.

Neither the sObject API nor the Metadata API includes the 'custom' boolean value in their footprint. We're discussing whether or not to include it in a future release, in fact, someone just asked me yesterday whether anyone actually uses this checkbox.

You could create a list view in the setup UI that filters based on the 'custom' checkbox and then use that list to enumerate your SOQL (where name <> "System Administrator"). But name is a difficult attribute to use for profiles in general to determine whether it's custom since it's possible for standard and custom profiles to have similar looking names (no __c to distinguish).

In the API, profile.name is actually the profile's label and doesn't follow normal API field behaviors. That label is used to generate the file name during a retrieve in the Metadata API but you'll notice that by using Daniel's package.xml definition to return all profiles, that the standard profiles are all predefined (e.g. System Administrator = Admin.profile) without any special 'standard' designation.

In the API, the profile Name attribute is also used to return the label of the profile. Unlike permission sets where we expose an API 'Name' attribute, profile only returns the equivalent of a label (SELECT Id,Label,Name, Profile.Name FROM PermissionSet WHERE isOwnedByProfile=true).

  • Would be helpful if you could expose it in the API. I was looking for a way to query for the names of standard profiles but found that its not been exposed. I have to go the ugly way of hardcoding the standard profile names for now. – jacksparrow007 Dec 26 '13 at 12:11
  • Quick update to my comment - starting in Spring '14 (version 30 of the API), we will support the custom boolean value for profile in the Metadata API (pg 317 of help.salesforce.com/help/pdfs/en/…). – Adam Torman Feb 10 '14 at 16:44
  • Can I do a SOQL to get the standard profile names? Something like 'select name from profile where iscustom=false' . Is this available now? – jacksparrow007 May 19 '14 at 10:24
  • As of the spring 17 release, you can accomplish this via SOQL and the field is API exposed. Full answer is here - salesforce.stackexchange.com/a/162218/27212 – jmdohn Feb 27 '17 at 14:56
0

I don't believe there is such a field you could pull through SOQL with the Partner or Enterprize API.

Maybe you could use the Profile.Description field to build an indicator of sorts. I believe by default the field will always be blank. You could put a value on your custom profiles to separate them from the built in ones.


The Metadata API will probably have the information you need to determine if the profile is custom or not.

UPDATE: I had thought a MetaData RetrieveRequest with <types> <members>*</members> <name>Profile</name> </types> would have been sufficient to find the custom profiles. Apparently not, as all you get back is the userLicense string in the .profile files. I think additional content is required in the RetrieveRequest to get the other possible field values. That said, none of the possible Metadata Profile fields will help you identify if the profile is custom. I had thought that fullName may have had a __c suffix like most other custom sObjects and custom fields.

See the Profile Metadata documentation.

0

Since Standard Profiles have many fields that are not editable, you can determine which profiles are custom by trying to toggle a permission. If you catch an error, its standard. If you don't it is custom.

Don't toggle a permission which will have an impact on users, choose one which is irrelevant to your org.

0

Phil Rymek suggested to toggle permission to check if profile is custom.

I have written a code which does that

public static Boolean isStandard( String profileId ) {
    List<PermissionSet> ps = [ select id from PermissionSet where IsOwnedByProfile = true and ProfileId = :profileId];
    Savepoint sp = Database.setSavepoint();
    Database.SaveResult sr = Database.insert(new ObjectPermissions(
        ParentId = ps[0].Id, 
        SobjectType = 'Account',
        PermissionsModifyAllRecords = true
    ), false);
    Database.rollback(sp);
    String defaultMessage = 'You can\'t create, edit, or delete records for this permission set parent because it\'s associated with a standard profile.';
    for ( Database.Error e: sr.getErrors() ) {
        if ( e.Message.contains(defaultMessage))
            return true;
    }

    return false;
}
        System.debug(LoggingLevel.ERROR, '@@@ 00eE0000000z6CjIAI: ' + isStandard('00eE0000000z6CjIAI') );
        System.debug(LoggingLevel.ERROR, '@@@ 00eE0000000z6ChIAI: ' + isStandard('00eE0000000z6ChIAI') );
        System.debug(LoggingLevel.ERROR, '@@@ 00eE0000000z6CfIAI: ' + isStandard('00eE0000000z6CfIAI') );

also it is possible to write method which consumes profile name:

public static Boolean isStandardProfile( String profileName ) {
    List<PermissionSet> ps = [ select id from PermissionSet where IsOwnedByProfile = true and Profile.Name = :profileName];
    Savepoint sp = Database.setSavepoint();
    Database.SaveResult sr = Database.insert(new ObjectPermissions(
        ParentId = ps[0].Id, 
        SobjectType = 'Account',
        PermissionsModifyAllRecords = true
    ), false);
    Database.rollback(sp);
    String defaultMessage = 'You can\'t create, edit, or delete records for this permission set parent because it\'s associated with a standard profile.';
    for ( Database.Error e: sr.getErrors() ) {
        if ( e.Message.contains(defaultMessage))
            return true;
    }

    return false;
}

        System.debug(LoggingLevel.ERROR, '@@@ Read only - standard: ' + isStandardProfile('Read Only') );
        System.debug(LoggingLevel.ERROR, '@@@ Administrator - standard: ' + isStandardProfile('System Administrator') );
        System.debug(LoggingLevel.ERROR, '@@@ PMO - custom: ' + isStandardProfile('PMO') );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.