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
JntshumakerJntshumaker 

Displaying a Different Visualforce Page based on Users Profile

I'm attempting to modify an existing appexchange page/button called "massedit".

 

I need to modify the page to display a different set of columns based on the users profile, I was able to find the following through the Salesforce documents, problem is this code is intended for something a little bit different than what i'm trying to do:

 

 

<apex:page action="{!if($Profile.Name !='System Administrator',
null,
urlFor($Action.Account.Tab, $ObjectType.Account,
null, true))}" standardcontroller="Account" recordsetvar="accounts" tabstyle="Account">

<!-- Replace with your markup --> 

This page replaces your Account home page for
all users except Administrators.
</apex:page>

 

I'm just not quite sure how to drop two separate visualforce pages within the IF statement, the page itself looks like the following, natively:

 

 

<apex:page standardController="Opportunity" recordSetVar="unused" sidebar="false">
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >
Note: All modifications made on the page will be lost if Return button is clicked without clicking the Save button first. 
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Return" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!selected}" var="opp" id="table">
<apex:column headerValue="Company" width="500px">
<apex:outputField value="{!opp.AccountID}"/>
</apex:column>
<apex:column headerValue="Name">
<apex:inputField value="{!opp.name}"/>
</apex:column>
<apex:column headerValue="Amount">
<apex:inputField required="true" value="{!opp.amount}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

Your problem seems to me the condition

 

rendered="{$Profile.Name =='Test User'}" 

 

Try this instead

 

rendered="{!IF($Profile.Name =='Test User', true , false)}"

 

similarly for other page block

Hope will help you

All Answers

Shashikant SharmaShashikant Sharma

You can not create two sections <apex:page /> in a VFP. What you need to do is to create two pageBlock, pageBlockSection and render them according to profile as per your requirement. Please elaborate your problem more if it does not help you.

JntshumakerJntshumaker

Thank you for the reponse, this makes sense, could you provide me with some example code of how you would display two different pageblocks based on profile?

Shashikant SharmaShashikant Sharma

Here is a sample code

 

 

<apex:page standardController="Opportunity" recordSetVar="unused" sidebar="false">
<apex:form >
<apex:pageBlock rendered="{$Profile.Name =='System Administrator'}" >
   <!--
Add Items to show for System Administrator
-->
</apex:pageBlock >
<apex:pageBlock  rendered="{$Profile.Name =='Some Other Profile'}">
<!--
Add Items to show for Some Other Profile
-->
</apex:pageBlock >
<apex:form >
</apex:page

 

JntshumakerJntshumaker

Thank you for the quick replies, I attempted to deploy the recommendations you had:

 

 

<apex:page standardController="Opportunity" recordSetVar="unused" sidebar="false">
<apex:includeScript value="{!$Resource.UtilJS}" />
<apex:form >

    <apex:pageBlock rendered="{$Profile.Name =='Test User'}" >

    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Return" action="{!cancel}"/>
    </apex:pageBlockButtons>

    <apex:pageBlockTable value="{!selected}" var="opp" id="table">

        <apex:column headerValue="Company">
        <apex:outputField value="{!opp.AccountID}"/>
        </apex:column>
        
    </apex:pageBlockTable>
    </apex:pageBlock>

    <apex:pageBlock rendered="{$Profile.Name =='Custom Standard User'}">
    
    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}"/>
        <apex:commandButton value="Return" action="{!cancel}"/>
    </apex:pageBlockButtons>

    <apex:pageBlockTable value="{!selected}" var="opp" id="table">

        <apex:column headerValue="Name">
        <apex:inputField value="{!opp.name}"/>
        </apex:column>
        
    </apex:pageBlockTable>
    </apex:pageBlock>

</apex:form>
</apex:page>

 However, when I open the page with the Profiles defined in the visualforce, nothing is display (no errors, just a "blank" salesforce page)

 

Shashikant SharmaShashikant Sharma

Your problem seems to me the condition

 

rendered="{$Profile.Name =='Test User'}" 

 

Try this instead

 

rendered="{!IF($Profile.Name =='Test User', true , false)}"

 

similarly for other page block

Hope will help you

This was selected as the best answer
JntshumakerJntshumaker

Perfect, performing just as desired.

 

Thank you

Joy_JacquesJoy_Jacques

Just wanted to second the thank you. This was just what I needed.