Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to do some conditional formatting for the Opportunity Amount field on a VisualForce page that just displays the currently set amount. There is a chance that the amount can be negative (due to carry over credits) and I want to be able to display the Amount in parentheses if it's negative.

I think I'm missing something basic about how to reference an object's fields, but I haven't been able to Google-up an example that could help me with this.

Here's my VF code:

<apex:outputText value="Opportunity Amount"></apex:outputText>
<apex:outputText value="{!IF(opportunity.Amount < 0, '$(' + opportunity.Amount + ')', '$' + opportunity.Amount)}"></apex:outputText>

I know I'm probably missing something very basic here, but would really appreciate some help.

Thank you!

share|improve this question
up vote 6 down vote accepted

In general, I would suggest to keep the logic at the controller layer, as opposed to the view layer.

I would do something like this


<apex:outputText value="{!myOppAmount}"/>

In Controller. (Assuming you have an opportunity property already)

public string getMyOppAmmount(){
    string s = (this.Opp.Amount > 0) ? '$' + this.Opp.Amount : '$(' + this.Opp.Amount + ')';
    return s;
share|improve this answer
Both answers are practical, but this one has one important advantage: expressions are evaluated and take up view state, while strings such as this take up less view state. – sfdcfox Dec 12 '13 at 15:31
Very good point @sfdcfox. Thanks – Chris Duncombe Dec 12 '13 at 15:33

Please make sure that you convert the number, opportunity.amount, to string using the TEXT() function so that the concatenation can be done.

<apex:outputText value="{!IF(opportunity.Amount < 0, '$(' + TEXT(opportunity.Amount) + ')', '$' + TEXT(opportunity.Amount))}"></apex:outputText>
share|improve this answer
Upvote for answering the question asked. – Shane McLaughlin Dec 13 '13 at 1:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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