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 getting some errors when I try to concatenate two variables value in apex:outfield tag. For example, if I have two variables a1 and a2, how can I get this concantenation: value="{!a1} {!a2}"> ?

share|improve this question
up vote 6 down vote accepted

I think you can't concatenate many variables or even use variables with an apex:outputField. This visualforce tag should be used with sObject fields only!

As workaround you can use apex:outputText instead where you can do concatenation like this:

<apex:outputText value="{!a1} {!a2}" />
<apex:outputText value="{!a1 + ' ' + a2}" />

Or if using multiple sObject fields you will need to use multiple apex:outputField tags, for example in a page block table:

    <apex:outputLabel value="My Label" />
        <apex:outputField value="{!object.Field1__c}" />
        <apex:outputField value="{!object.Field2__c}" />
share|improve this answer

If it were not for the fact that it is an <apex:outputField>, you could use

{!a1 + a2}

You can only have one {!...} part in an attribute, but you can include a complete calculation within that. E.g. {!a1+5} or {!a1+a2+'moreText'} is usually perfectly valid (given the types match, of course).

Now, in an outputField {!..} part, you can only reference one field. So what you could do is make a formula field 'concatField', concatenate your values in there, and then display them using

share|improve this answer if I have two variables, Object1.a1 and Object1.a2 , what is the right form ? – Tonino Tripodi Jun 26 '14 at 12:46
Sorry, I didn't initially see the outputField part. Updated the answer: I would suggest using a formula field if you want to keep it to one outputField. – Willem Mulder Jun 26 '14 at 12:53

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.