+ Start a Discussion
SteveMouSteveMou 

Visualforce Page require fields based on Different Profiles?

Does anyone know if it is possible on a single VF page to require a field ( Required="True") for only a specifc User Profile instead of just for all profiles?  I have an Opportunity VF page where I only want a certain group of users based on their Profile to have the field as required.

 

My only option I see at the moment is creating separate VF pages and then assigning them to specific profiles.

Best Answer chosen by Admin (Salesforce Developers) 
SteveMouSteveMou

Thanks for steering me in the right direction!! I got it:

 

required="{!OR($Profile.Name=='Profile1',$Profile.Name=='Profile2')}"/>

All Answers

sfdcfoxsfdcfox
What's wrong with using standard page layouts? You can make a layout, assign it to a profile, and make it required for that layout.

Of course, if it's because you're enhancing a Visualforce page for other reasons, then you'll just need to conditionally require the field using a merge field:

required="{!$Profile.Name='Profile Name'}"
SteveMouSteveMou

I wish I could use the Standard page layout, however we have the need for the VF page for other reasons.

 

So are you saying below I could change this code here:

 

<!-- <apex:outputField id="ofBDRep" value="{!opportunity.OwnerId}"/> --> <apex:inputField id="ifRFPBDREP" value="{!opportunity.RFP_BD_Rep__c}" required="true" />

 

To be:

 

<!-- <apex:outputField id="ofBDRep" value="{!opportunity.OwnerId}"/> --> <apex:inputField id="ifRFPBDREP" value="{!opportunity.RFP_BD_Rep__c}" required="{!$Profile.Name='BDREPProfile'}"

 

 

If so, can I specify more than just the 1 profile? I have a couple different profiles that I want to make it required for.

 

Thanks this is most helpful so far.

SteveMouSteveMou

Thanks for steering me in the right direction!! I got it:

 

required="{!OR($Profile.Name=='Profile1',$Profile.Name=='Profile2')}"/>

This was selected as the best answer