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.
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:
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?
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">
</apex:page>
Hope this helps.
The following should redirect to sorry_page:
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:
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.
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?
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