Search code examples
salesforceapex-codevisualforceapex

Visualforce IF statement: texted wrapped around apex


I have a VF page with the following code:

<p>Hi {!Report_Owner.Name}, You achieved your target
{!IF(report.formulaMetric = 100,
"!",
" and surpassed it by {!report.differenceFM}% ")} 
You are not required to do anything else. Thank you.</p>

Unfortunately, at the moment (when formulaMetric = 101 or higher) it returns the following:

Hi Robert, You achieved you target, and surpassed it by #{!report.differenceFM}% 
You are not required to do anything else. Thank you.

As you can see, instead of rendering differneceFM at a number (eg 1%) it renderes it as text. I know this is probably something silly I am missing, but how do I make sure that the variable associated with {!report.differenceFM} is rendered as apposed to it being recognized as part of a string?

Thanks!


Solution

  • Change to:

    {!IF(report.formulaMetric = 100,"!"," and surpassed it by" +report.differenceFM +"% ")}