+ Start a Discussion
Parvinder ChanaParvinder Chana 

use of if condition in visual force page

I'm creating a visual page page to show custom link to reports and everything worked great.
I have few custom fields on account object which I will use to show custom link and I need help to use if condition something like this

if account.Relation = "Partner" then show link to a report
else if account.relation = "Customer" then show link to another report
else don't show link at all.

I'm sure it is achieveable but need help.

James LoghryJames Loghry
Sure you can use IF logic here.  If you want the text to stay the same, you could do something like the following:
<apex:outputlink value="{!IF(account.Relation == 'Partner','/link_to_report_1',IF(account,Relation=='Customer','/link_to_report_2','/link_to_report_3')}">Click to view report</apex:outputLink>

Otherwise, you could use the rendered attribute with an IF statement:
<apex:outputLink rendered="{!IF(account.Relation == 'Partner',true,false)}" value="/link_to_report_1">Click to view report 1</apex:outputLink>

<apex:outputLink rendered="{!IF(account.Relation == 'Customer'',true,false)}" value="/link_to_report_2">Click to view report 2</apex:outputLink>

<apex:outputLink rendered="{!IF(OR(account.Relation == 'Partner',account.Relation == 'Customer'),false,true)}" value="/link_to_report_1">Click to view report 3</apex:outputLink>

Parvinder ChanaParvinder Chana
Thanks for the reply. This what I did, let me know if one solution is better than another?

<apex:variable var="d" value="/reportid?pv0={!SUBSTITUTE(SUBSTITUTE(Account.Name,'&', '%26'),'#','%23')}"/>

<apex:variable var="l" value="{!IF((CONTAINS(Account.Relationship_A__c, 'Owner') || CONTAINS(Account.Relationship_B__c, 'Owner')  || CONTAINS(Account.Relationship_C__c, 'Owner')) , 'Show me locations owned by this owner ' &  Account.Name & '?' ,  '')}" />

        <a href="{!IF((CONTAINS(Account.Relationship_A__c, 'Owner') || CONTAINS(Account.Relationship_B__c, 'Owner')  || CONTAINS(Account.Relationship_C__c, 'Owner')) , d,  '')}" target="_blank">{!l}</a>&nbsp;&nbsp;&nbsp;

Basically, I stored the information in a variable then using that in link?