I have the following code within my visualforce page, this ensures only users with the Portal profile can see the page, otherwise they are shown the SFDC page.

<apex:page standardController="News__c" action="{!if($Profile.Name =='Portal', null,
        urlFor($Action.News__c.View, News__c.Id, null, true))}" tabstyle="News__tab">

How can I edit this code so that it can have multiple conditions? i.e. Portal AND Standard profiles can view the current page.


Since you are only using the StandardController, you can just do something like this...

action="{!if($Profile.Name == 'Portal' || $Profile.Name == 'Standard', ...>

As a suggestion though, this type of logic is much better suited for a custom controller. Sticking a lot of conditional logic in your VF markup is kind of an anti-pattern IMO.


K, the following answer is one way to add multiple conditions via an Apex Controller. Its not the only way to do it.

Google "Visualforce functions" to see how to add an OR() function to your VF logic.

Below is an example of achieving the same conditions using Apex

The action parameter of apex:page invokes a method from a controller. You'd can to write a controller extension similar to the following:

VF Page:

<apex:page standardController="News__c" extensions="NewsExtension" action="{!profileCheck}">


public class NewsExtension {
    // constructor
    public NewsExtension(ApexPages.StandardController sCon){ }

    public PageReference profileCheck(){
        String userProfileName = [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId()].Name;
        if(userProfileName == 'Portal' || userProfileName == 'Standard')
            return null; // no - redirect
        return new PageReference('/theRedirectPage');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.