I am adding the field value i.e number type with the apex:variable but getting the error

Incorrect parameter type for operator '+'. Expected Text, received Number


1 Answer 1


I was able to get a very similar to piece of code to yours to work - but I found that I couldn't even compile the page using outputField - You should only use outputField for values that are directly tied to a sObject value.

Change to outputText and also verify that wrapRec.T_Price__c is in fact a number value.

Failing that, try wrapping the value to be added in a VALUE() function.

EDIT Here is the code I used. I used a list of accounts in the controller.

<apex:pageBlock >
    <apex:pageBlockSection columns="1" collapsible="false" >
        <apex:pageBlockTable value="{!acctWrapper}" var="acct">
            <apex:column value="{!acct.acctId}"/>
            <apex:column value="{!acct.name}"/>

            <apex:column >
                <apex:variable var="total1" value="{!total1 + acct.num}" />
                <apex:outputText value="{!total1}" />

            <apex:column >
                <apex:variable var="total2" value="{!total2 + acct.num}" />
                <apex:outputText value="{!total2}" />


Here is the wrapper code:

public class Wrapper {
    public String name {get; set;}
    public Id acctId {get; set;}
    public Integer num {get; set;}

    public Wrapper(String name, Id acctId, Integer num) {
      this.name = name;
      this.acctId = acctId;
      this.num = num;

And here is where I build the wrapper list:

//defined at top of class
public Wrapper[] acctWrapper {get; set;}

accounts = [SELECT Name, Id From Account LIMIT 20];
acctWrapper = new Wrapper[]{};
Integer count = 0;
for (Account a : accounts){
    acctWrapper.add(new Wrapper(a.Name, a.Id, count));
  • "T_Price__c' is number type. Can you explain with example code?
    – sugandhi
    May 4, 2015 at 5:58
  • Updated - try now May 4, 2015 at 6:14
  • Actually,I am adding the field value to the total that's not working for the custom object field. It is showing me the error message when i add the total1 and the field in value attribute.My wrapper class have getter and setters. I want to do exactly total like this example... [link] (salesforce.stackexchange.com/questions/20563/…)
    – sugandhi
    May 4, 2015 at 7:42
  • Updated again - try this one. This uses a wrapper class and I'm adding a number from the wrapper class to the apex:variable - no errors. May 4, 2015 at 9:48
  • i am using custom object field i.e number type instead of count variable.It's not working.
    – sugandhi
    May 8, 2015 at 7:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .