I am getting always 0 as a result of total. I am using apex:vairable, initialing it before apex:block. Inside the apex:block I am adding the field of object i.e number type with apex:variable and fetching it's value {!total} inside the apex:block. My code is:

 <apex:variable value="{!0.00}" var="total"/> 
<apex:pageBlockTable title="Your Total" value="{!selectedWrapperList}" var="wrapRec" rendered="{!selectedList}" >
<apex:column ><apex:outputText value="{!wrapRec.Place_Price__c}" />
    <apex:variable var="total"  value="{(!total + wrapRec.Place_Price__c)}" />
    <apex:facet name="footer"> 
    <apex:outputText value="{!total}"/>

I am following the code in below link: code followed

Any assistance with code are much appreciated!


Unfortunately ,it's not guaranteed to work with pageblocktable. In fact, SF does not support its use for iteration. However, if you want to use this , please use it with repeat where there are high possibility to work. I have tried below and it's worked

<apex:page controller="accountlist">
       <apex:variable value="{!1}" var="total"/> 
           <apex:pageBlock >
            <apex:repeat value="{!acclist}" var="v">
               <apex:variable var="total"  value="{!total + 1}" />


    public class accountlist {

        public list<account> getAccList() {
            return [select id from Account limit 20];

| improve this answer | |

You have a typo in your binding expression. This:

value="{(!total + wrapRec.Place_Price__c)}"

Should be this:

value="{!total + wrapRec.Place_Price__c}"
| improve this answer | |
  • This might fix your problem in your previous question too... – Caspar Harmer May 8 '15 at 8:24
  • by changing this: it's giving me error message NOT is not a valid function. – sugandhi May 8 '15 at 8:24
  • removed the brackets - try again. – Caspar Harmer May 8 '15 at 8:27
  • still getting 0 – sugandhi May 8 '15 at 8:37
  • Either wrapRec.Place_Price__c is always 0, is not a number - or is a decimal perhaps, or you need to change your <apex:variable> to be an integer. It just has to be that. Can you test this by using a normal Integer defined in the controller? You just have to work out what your values are - that's how you debug. I can't help you any more that this, sorry. – Caspar Harmer May 8 '15 at 8:43

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.