Sometime it is required to override the standard salesforce action for tabs or view pages with a custom visualforce page and that too for some of the profiles OR if the record meets certain criteria, but at the same time we want to keep the standard page for rest of the profiles or records which do not meet the criteria.
Let's take an example which would help you to understand this. Suppose we need to show user a custom visualforce page with some details on it when Account tab is clicked and the only exception is System Administrator who should rather see the standard tab page.
Though the logic can be defined in an apex class which will redirect user to the desired page. But from what I know from my experience is we should avoid writing the code untill it is possible to have an effective solution using configuration only.
Here is the simple solution:
- Write the page logic like the one given below :
<apex:page action="{!if($Profile.Name !='System Administrator', null, URLFOR($Action.Account.Tab, $ObjectType.Account, null, true))}" standardController="Account" recordSetVar="accounts" tabStyle="Account"> This page replaces your Account home page for all users except Administrators. </apex:page> - Change the security setting for the vf page so that to allow all the profiles to use it.
- Override Account Tab with "<OverrideExceptFromAdmin>" (Name of your visualforce page) page.
and you are done with it :)
If you want to have an idea about the function URLFOR and each parameter of it, please go through the below salesforce documentation link:
No comments:
Post a Comment