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
Koen (BvD)Koen (BvD) 

Detect standard user

For some obscure reason you can no longer grant access to custom objects to the standard user profile. I am not going to rant about how stupid this is (though I feel like) but I wanted to keep compatibble and allow the use of the apex code even for standard users. So I would like to detect the standard profiles (i.e. those that salesforce does not allow to gain access to custom objects). All I could come up with is test on the profiles names

 

    public boolean isStandardUserProfile ()
    {
        String ProfId= UserInfo.getProfileId();
        List<Profile> lstP = [select name from Profile where id =: ProfId];        
        Profile p = lstP [0];
        return p.name == 'Standard user' || p.name == 'Marketing User' || p.name == 'Contract Manager' || p.name == 'Solution Manager';        
    }

 

But this is not very clean, and what is worse it doesn't even work if the user has another language than english configured as apparently even the profile names are translated.

What can I do? All I need is to be able to make the distinction between a user not having access to the custom object because his profile is configured not to allow access and users from standard profile where salesforce does not allow you to configure access. Note that this is really inconsistent as they allow you to edit for standard users the field level security of custom objects, but you can never test on these settings as the access to the object is disabled.

Jia HuJia Hu
Basically, use profile id as the condition, it will not change in the different languages.
Koen (BvD)Koen (BvD)

Thanks for the suggestion, this was also my first idea, but I don't see how I can use that. The id of the profiles change with the organisation, so I can never detect standard users in other organisations.

benvkbenvk

you can do things like [ select Profile.UserType From User ] - i think user type can be 'Standard' which might be what you're looking for?

Koen (BvD)Koen (BvD)

This is something different. The profile.usertype applies to the type of license.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_profile.htm

What I mean by standard is one of the predefined profiles created on each salesforce organisation, in contrast with the custom profiles created by the administrator.

 

Koen.

Jia HuJia Hu
It seems Salesforce didn't support this by API.
But you can query the Profile object and order by CreatedDate field. The standard profiles were created at the very beginning when this org. was created and all the createddate is same even to the second in this field.

The drawback is it does not work for the standard profiles added by Salesforce later, such as Chatter,...