I am trying to display fields with some static text based on another field's value.

<apex:repeat value="{!caseHistory}" var="casHistory">

                    <div class="section1">
                        {!casHistory.CreatedBy.LastName}, {!casHistory.CreatedBy.FirstName}
                    <div class="section2" >
                        Changed {!casHistory.Field} from {!casHistory.OldValue} to {!casHistory.NewValue}
                    <div class="section3">


Here for section2, I wanted to check implement something like this:

!IF((!casHistory.OldValue) != null),(Changed {!casHistory.Field} from {!casHistory.OldValue} to {!casHistory.NewValue}), ({!casHistory.Field})  }

I had this If statement in a <apex:outputtext value="IF STATEMENT"> tag, but seems not working. I might be doing something wrong, which I am not sure.

  • Does it even save? You have extra exclamation points (!), mostly paired with extra curly brackets ({}). – Adrian Larson Jun 22 '17 at 18:43
  • Yes it did. But the displayed output has the fields({!casHistory.OldValue} , {!casHistory.NewValue} and others) along with the IF statement. – Arnold Jr. Jun 22 '17 at 18:47

Your syntax is a little bit all over the place. Here's how I would structure the format in a clean (easy to read), multi-line manner. Here I will change casHistory to history for my own sanity:

    /*value_if_true*/ 'Changed ' & history.Field &
        ' from ' & history.OldValue &
        ' to ' & history.NewValue,
    /*value_if_false*/ '???'

Now, you have to put this formula into a merge statement ({!...}), so it would look like:

<apex:outputText value="{!IF(/*condition*/..., /*value_if_true*/..., /*value_if_false*/...)}" />

A simpler alternative would be to just specify condition in a rendered attribute:

<apex:outputText rendered="{!NOT(ISNULL(OldValue))}" value="{!'Changed ' & history.Field & ' from ' & history.OldValue & ' to ' & history.newValue}" />
  • Sorry, I am not sure if I understand the above IF Statement well. If I use a text with quotes inside a <apex:outputText> 's value, I would get errors. – Arnold Jr. Jun 22 '17 at 19:06
  • @ArnoldJr. You can just change to single quotes then...or use single quotes to wrap the merge field. – Adrian Larson Jun 22 '17 at 19:08
  • Syntax error persists. – Arnold Jr. Jun 22 '17 at 19:27
  • I tried the alternative solution, even I got an error which shouldn't be getting: Incorrect parameter type for function 'not()'. Expected Boolean, received Text. Code: <apex:outputText rendered ="{!NOT(ISNULL(!casHistory.Field))}" value="{!'Changed ' & (!casHistory.Field) & 'from ' & (!casHistory.OldValue) & 'to ' (!casHistory.NewValue)}"> </apex:outputText> – Arnold Jr. Jun 22 '17 at 22:18
  • 1
    Missing concatenation operator (&) before the final text value mentioned in that error. – Adrian Larson Jun 22 '17 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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