You need to sign in to do that
Don't have an account?
Roger Pavelle
Can you put a conditional inside an apex tag?
I'm importing a database integer value into an apex page.
In one place, I would like to replace the value with text (if value = 1 text=Bad, else if value = 2 text = blah, etc.).
In a different place, I'd like to color code backgrounds based on the value (If value =1 background = red, else if value = 2 background = yellow, etc.)
I know I can figure out a workaround for the first example, but since the second one needs something programmatic. Is there a way to put an if statement (or case statement or other conditional statement) in the apex tag?
In one place, I would like to replace the value with text (if value = 1 text=Bad, else if value = 2 text = blah, etc.).
In a different place, I'd like to color code backgrounds based on the value (If value =1 background = red, else if value = 2 background = yellow, etc.)
I know I can figure out a workaround for the first example, but since the second one needs something programmatic. Is there a way to put an if statement (or case statement or other conditional statement) in the apex tag?
You can try this:
1. First create a css class like this:
<style>
.redbg{
background-color: red;
}
</style>
2. And attach the class to apex element with if clause:
<apex:inputText id="field_id" styleClass="{!IF(value == 1,'redbg',IF(vallue == 2,'yellowbg',etc))}"/>
hope this help.
All Answers
1) <apex:repeat value="{!relatedTo.Legal_Requests__r}" var="legalRequest">
<tr>
<td>
{!IF(AND(legalRequest.Request_Type__c == 'Sales', legalRequest.Service_Type__c == 'New Business'), <a href ="https://fico--dev1.cs30.my.salesforce.com/{!legalRequest.Id}">{!legalRequest.Name}</a> , false)}
</td>
</tr>
</apex:repeat>
2) You can also put all the condition statement in your extension or controller class and return what final results.
That are other options also such as scriptings.
Thx
You can try this:
1. First create a css class like this:
<style>
.redbg{
background-color: red;
}
</style>
2. And attach the class to apex element with if clause:
<apex:inputText id="field_id" styleClass="{!IF(value == 1,'redbg',IF(vallue == 2,'yellowbg',etc))}"/>
hope this help.
Any suggestions?
Here is the IF statement that I am trying to use. I get an error if I put this into the Search Results block or if I try to attach it to the pageBlockTable tag (the latter because it doesn't recognize the variable name.
<apex:outputPanel styleClass="{!IF(bol.Edibility__c == 1,'red',
IF(bol.Edibility__c == 2,'yellow',
IF(bol.Edibility__c == 3,'blue',
'green')))}">
Here is the code for the table.
<apex:pageBlock title="Search Results" id="bolete_list">
<apex:outputText >{!showResultSize} of {!showRecordSize} records displayed</apex:outputText>
<br/>
<apex:pageBlockTable value="{! Boletes }" var="bol" style="width: 100%">
<apex:column width="75">
<apex:outputLink value="/apex/boleteDetailView?id={!bol.Id}" id="viewLink">
View
</apex:outputLink>
</apex:column>
<apex:column width="75">
<apex:image id="imageURL" url="{!bol.ImageURL__c}" height="75"/>
</apex:column>
<apex:column value="{! bol.genus__c }">
<apex:facet name="header">
<apex:commandLink action="{! sortByGenus }" reRender="bolete_list">Genus
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{! bol.species__c }">
<apex:facet name="header">
<apex:commandLink action="{! sortBySpecies }" reRender="bolete_list">Species
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{! bol.Common__c }"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:pageBlock>
Can you make sure that your visualforce page have controller? Because when you want to call field from any object you must have a controller embedded on the pages, something like:
<apex:page standardController="Opportunity" extensions="ShowUnitController" sidebar="false">