+ Start a Discussion

Checking if user is system admin

I want to check if user is system administrator in visual force page. if not then redirect to another page.

Please help me.


You can get the current user's profile using UserInfo.getProfileId().  Then you can look up the profile name via SOQL and see if it is 'System Administrator'.


If you then create a page level action method to checks this, you can redirect the user before anything is rendered.


I'd rather check the same using below code but i cant understand the parameters below. like null etc.

if profile.name!= System Administrator then it should redirect to another page.

"{!if($Profile.Name !='System Administrator', null,urlFor($Action.Account.Tab, $ObjectType.Account,null, true))}"


please help me with this


apex:page action="the code i have written above"


So are you having problems with the redirect?


yes.. how do i redirect it to a page i created. its called sorry_page?


Tryout the sample code given below :


<apex:page action="{!if($Profile.Name == 'System Administrator',$Page.testconfirm,URLFOR($Action.Account.Tab, $ObjectType.Account,null,true))}" standardController="Account" recordSetVar="accounts" tabStyle="Account">



Hope this helps.


The following should redirect to sorry_page:



<apex:page action="{!if($Profile.Name !='System Administrator', null,urlFor('/apex/SorryPage'))}">




it didnt work.. :(  its going to a page which is not sposed to be viewed by other users.


Can you clarify how it isn't working?


I.e. which page does sysadmin end up on and which page does non-sysadmin end up on?


Ah - I misunderstood your earlier posts, so sys admin is sent to sorry page rather than the other users.  Simply swap the urlfor and null parameters like so:



<apex:page action="{!if($Profile.Name !='System Administrator',urlFor('/apex/SorryPage')), null}">



<apex:page action="{!if($Profile.Name !='System Administrator',urlFor('/apex/SorryPage')), null}">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection title="Admin Page" columns="1" > 
            <apex:outputField value="{!Topic__c.Name}"/>
            <apex:outputField value="{!Topic__c.description__c}"/>

            <apex:pageBlockTable value="{!MessageList}" var="item" >
                <apex:column value="{!item.text__c}" width="850"/>
                <apex:column headerValue="Action"  style="white-space: nowrap"  >    
                    <apex:outputLink title="" value="/apex/approve?id={!item.id}" style="font-weight:bold">review</apex:outputLink>                         



this is the admin_page. when user goes to this page it should check whether its user admin or not before rendering the page. Right??


Yes.  I've tried this in my dev org - the sys admin sees my page and other users go to the sorry page.

Dogen ZenjiDogen Zenji

I wanted to raise this old thread from the dead because of something I just noticed.  Salesforce allows one to create a custom profile with the same name as the standard System Administrator profile.  If you encounter an org with such a profile, this logic would fail.  Checking that Profile Name equals "System Administrator" would also fail in any language but English.  Why don't they have an IsCustom field on the Profile object?  Since they don't, any suggestions for how else to ensure a user is logged in as a real System Administrator?

Thibault WeberThibault Weber

You're right, we also have problems to identify system administrators depending of the language setting.

Profiles should have a field "DeveloperName"! 

Vote for it

Alex Awan 5Alex Awan 5
I have read some guide about it, You can see here (https://reviewlog.org/)