Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Salesforce by (11.9k points)

I need help with the right VisualForce syntax to use "or" logic. The code I'm using is:

<apex:page action="{!if($User.Alias !='Item1',

    null,

    urlFor($Action.Account.Delete, $CurrentPage.Parameters.id, [retURL='/001'], true)

    )

    }"

  standardController="Account">

     <apex:pageBlock >

        <apex:PageMessage summary="You are not allowed to delete Accounts"

            severity="Warning"

            strength="3"/>

        <apex:pageMessages />

    </apex:pageBlock>

    </apex:page>

On the first line:

{!if($User.Alias !='Item1',

I need to specify more than one item using "or" logic, so that the the IF statement will be evaluated if any of the specified "Items" are true. I'm going for something like this, but I don't know what the right syntax is:

{!if($User.Alias !='Item1', OR 'Item2', OR 'Item3',

Thanks for your assistance and patience!

1 Answer

0 votes
by (32.1k points)

You can do it either with logical operators or with formula functions.

https://help.salesforce.com/HTViewHelpDoc?id=customize_functions.htm

Here's what I call "programmer's syntax" because it uses the pipes (||) and ampersands (&&); operators are easier to read for developers.

IF($User.Alias = 'JohnDoe' || $User.Alias = 'JBloggs' || $User.Alias = 'FooBar',

    value_if_true,

    value_if_false

)

You can also use "Excel syntax" where you have OR() a function that can take any amount of parameters.

IF(OR($User.Alias = 'JohnDoe', $User.Alias = 'JBloggs', $User.Alias = 'FooBar'),
    value_if_true,
    value_if_false
)

Browse Categories

...