How to use ternary operator in Visualforce page?

How to use ternary operator in Visualforce page?

Visualforce page doesn’t support ternary operator. But, Apex support.

Visualforce page supports IF function. We can achieve the same using this.

Syntax:

IF ( logical_test, value_if_true, value_if_false )

Example:

{! IF( Account.Size__c == null, ’10’, Account.Size__c ) }

In the above example, if the Account’s Size is null, it will default to 10. Else, it will display the Account’s size.

Leave a Reply