0

i cloned sys admin profile,cloned profile has every access,now how can i check the cloned profile has admin accesss, using apex

Thanks.

  • What do you mean by Admin Access? Usually Cloned profile will be similar to its parent's profile. So it will have same access levels. – Rohit Mourya Feb 23 '17 at 14:20
  • @RohitMourya yes, the cloned profile will have similar permissions as its parent profile but i wanted to check if the profile had all permissions similar to system admin using apex.. – Anu Feb 23 '17 at 14:27
3

This really depends on how you define an Administrator but generally anyone with the "Modify All Data" can, literally, modify all data and thus could be referred to as an Administrator.

You can query for this:

SELECT Name FROM Profile WHERE PermissionsModifyAllData = true

This would just return all Profiles where the "Modify All Data" setting is true.

However, if you have a different criteria, you could simply query for that instead. For instance:

SELECT Name FROM Profile WHERE PermissionsAuthorApex = true

Would return all users who can write (author) Apex.

You could then check this in Apex against the running user using something like below:

private final Boolean isDeveloper = [SELECT PermissionsAuthorApex FROM Profile WHERE ProfileId = :UserInfo.getProfileId()].PermissionsAuthorApex;

public String dev() {
    String s;

    if (isDeveloper) {
        s = 'They are a developer.';
    }
    else {
        s = 'Not an dev.';
    }

    return s;
}

Edit

There's a great question/answer here from @AdrianLarson who explains in a bit more detail about permissions which is definitely worth a read.

|improve this answer|||||
  • @DanJones- Don't we have any option to find from which standard profile my profile has been cloned in APEX? – Samir Feb 23 '17 at 14:33
  • @Samir I don't believe there is, no. Theoretically, you could clone a profile from System Administrator and reduce the permissions down to that of a Read Only profile. Then knowing what the profile was cloned from becomes fairly redundant. – Dan Jones Feb 23 '17 at 14:37
  • Yes.It will become redundant but might help other in some cases – Samir Feb 23 '17 at 14:39
  • @Samir Maybe! For now though you're unfortunately stuck with defining what an Admin is and querying for those permissions as I've described above. If this is important, I'd suggest writing a Utility class so you can reuse the code you use to check if someone is an admin. – Dan Jones Feb 23 '17 at 14:41
1

To do what you're asking, you'd need to query for the specific permissions you want to check for that an Admin Profile has on an object. This answer to a question provide a bit more detail on how to do that. What you'll also want is a list of all the permissions which you can find at What does each permission on a user's profile mean?.

|improve this answer|||||
  • It would have been great if there was a cloneFrom field on profile – Samir Feb 23 '17 at 14:39
0

Actually, as it was said before, clone an Admin profile with the whole permissions is redundant, but I guess you would like to remove or add permissions with total freedom, according your requirements. The easyiest way I found to check permissions is downloading Profile object, filtering only System Administrator Profile and the cloned profile, and then, check Permissions fields. You could compare them manually, or download and copy them to an Excel file, where you could use formulas to compare only those fields. I wouldn't do it by Apex, but well, you could query only Administrator Profile and the cloned one, and then, iterate all permission fields and return a boolean value. You could check Permissions are enabled by boolean values at Permissions*[PermissionName]* fields at this document. I had the same doubt before about knowing from which profile someone could have cloned other one, but I couldn't find anything.

|improve this answer|||||

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.