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
Michael MarchesiMichael Marchesi 

Is it possible to have a VF page and a standard page for one object and render them based on user Profile

Hi everyone,

I was wondering if it was possible to load a standard page for one user profile (i.e. content manager) but if the user profile is different (i.e. account manager) load a custom VF page? How would I go abouts to achieve this?

Ajay Ghuge 6Ajay Ghuge 6
Hi Michael,

Yes it can be achieved using following way : 

I am providing a solution for standard object Contact. 

IMP: Click on the new button on Contact and copy the URL 

Step 1: Create an apex class as below 

public with sharing class ContactController {
    String MyProflieName;
    public ContactController (ApexPages.StandardController stdController) {
        List<Profile> PROFILE = [SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId() LIMIT 1];
        MyProflieName = PROFILE[0].Name;
    public pagereference doRedirect(){
        if(MyProflieName == 'System Administrator'){
            Pagereference pg = new pagereference('' ); // Paste URL copied in IMP 
            return pg;
            return new pagereference('/apex/DemoVisualForce'); // Custom VF page

Step 2 : Create a VF page as below : 
<apex:page standardController="Contact" extensions="ContactControlle " action="{!doRedirect}"> </apex:page>

Step 3: Override the new button of contact with the above page.

Now enjoy the redirecting !!!! :D

Mark this as solved if the information helps so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Michael MarchesiMichael Marchesi
Hello Ajay,

I have found a simpler solution and it was to just add an "action" tag to the <apex:page>. It looks something like this:
<apex:page standardController="Account"
      action="{!if(contains($Profile.Name,'Account Manager'), '', URLFOR($Action.Account.View,Account.Id, null, true))}" >

I was wondering now as a learning experience, what are the differences between the above solution using the "action" tag and the solution you propose.

Thank you,

Ajay Ghuge 6Ajay Ghuge 6

Both of the implementations are correct. If you check I also have used the action tag but in a different way.

You can mark any answer as the best answer and mark it as resolved.