function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GSBassoGSBasso 

How to query for only custom profiles?

There must be some way to tell because both the Profile detail page and the enhanced list view indicate whether the profile is custom.

Jeremy-KraybillJeremy-Kraybill

Surprisingly, I don't think that data is exposed through the fields on Profile. If you only need to differentiate between the very original profiles that came with your org, you could use CreatedDate, but that's not really ideal. Another less-than-ideal approach would be to query for the profiles that don't have one of the standard profile names, since standard profile names are not editable.

 

If you provide some more info on what you are trying to accomplish, there may be another solution.

 

Hope that helps

 

Jeremy Kraybill

GSBassoGSBasso

All our custom profiles are named with a common prefix so I actually am able to retrieve just the profiles I need.

 

I was just curious how to do it in a general way but I guess surprisingly it's not possible.

 

Thanks for taking the time to reply.

Ritesh AswaneyRitesh Aswaney

Hey,

Salesforce have 6 standard profiles, and the names have remained fairly constant. So you could these couple of lines of code to query for the custom profiles.

 

 

List<String> standardProfileNames = new List<String>{'System Administrator','Standard User','Read Only','Solution Manager','Marketing User','Contract Manager'};
Profile[] customProfiles = [Select Id, Name from Profile where Name NOT IN :standardProfileNames];
System.debug(customProfiles);
Of course you wanted to completely future proof yourself, you could store the names of the Standard Profiles as a comma separated list in a Custom Setting ! :)

 

ebiebi

In fact, we can create a custom pfoile whose name is the same as standard profiles while two or more custom profiles cannot have the same name.

 

As long as I know, the only way to identify them from each other is to compare their CreatedDate and consider the older one as the standard profile.

sfdcfoxsfdcfox

The only other method I can divine would be to attempt to change a standard permission using system mode (a class that does not use "with sharing"). If the change fails, it's a standard profile, otherwise it's a custom profile. Unfortunately, this would probably trigger the "mixed DML" error message if you attempted it in conjunction with any other DML statement.