I have this custom label in a Visual Force page: {!$Label.fb_contact_cs_title}

I want to first have an in-page conditional statement. Then I want to put that variable into the custom label.

{! if case.origin = 1, variable = 10; if case.origin = 2, variable = 20 }
{!$Label.fb_contact + variable}

You can declare a variable and set the conditional value like this:

<!-- Declare a variable and set it's value. If it's not 10 or 20 it'll be 0 - assumption -->
<apex:variable value="{!IF(case.origin == 1, '10', IF(case.origin == 20, '20', '0'))}" var="myVar" /> 

Then you can use it anywhere you like, just like a normal merge field:

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

In your case just concatenate it to your label.


Another route you can go is in the custom label you place the spot for your variable. This works great regardless of if you are putting the variable at the end or in the middle. So lets say that $Label.Hello has 'Hello {0} I am a {1}' in the value. You can call it like this

<apex:outputText value="{!$Label.Hello}" > <apex:param value="world" /> <apex:param value="programmer" /> </apex:outputText>

The resulting output will be 'Hello world I am a programmer'

  • This doesn't work for me in VF email template - is it supported there?
    – mascot
    Jan 16 '17 at 8:29

You can use the apex:variable to get the correct variable. I have used the Case function from salesforce to determine the variable based on the case.origin and then dynamically get the label

<apex:variable id="variable" value="{!CASE(case.origin,'1','10','2','20','0')}" var="variable"/>
 the label is  {!$Label['fb_contact'+variable]}

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.