function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RarLopzRarLopz 

Visualforcepage Grand total not diplaying

I am trying to get the total count of all records in the list, and display it. Value not displaying . 
 
<apex:page controller="CASReportController">
<apex:form >
    <apex:pageBlock title="JSON Deserialized Response">
    <apex:pageBlockButtons >
        <apex:commandButton value="submit" action="{!deserialize}" reRender="DealerBlock"/>
    </apex:pageBlockButtons>
			
    <apex:pageBlockSection id="DealerBlock" columns="1" title="RollUp Summary >

    <apex:repeat value="{!wrapper}" var="cap1">
                    
    <apex:pageBlockTable value="{!cap1.caPerformanceRecordList}" var="cap" width="100%">

    <apex:column headerValue="Reporting Period" value="{!cap.reportingPeriod}"/>
                            
    <apex:column headerValue="FS Integration Type Code" value="{!cap.financeSourceIntegrationTypeCode}"/>
                            
    <apex:column headerValue="IDL Plus" value="{!cap.idlPlus}"/>
                            
    <apex:column headerValue="Credit Application Source Code" value="{!cap.creditApplicationSourceCode}"/>
                            
    <apex:column headerValue="Submission Count" value="{!cap.submissionCount}" />
                               

<!-- Generating CASubmissionCount total --> 

<apex:variable var="total" value="{!cap1.appTotal}" />		 							

<!--footer of the SubmissionCount -->
     <apex:facet name="footer">           									
          Total Count: <span class="t1"></span>   			   <!--  expecting Total Count = 7 --    submissionCount of one record is 2 and other record is 7 as seen in json string >							
     </apex:facet> 
                             
 </apex:pageBlockTable>
</apex:repeat>            
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

------------------------------------------------------------
public with sharing class CASReportController {
    
@AuraEnabled
    
public list<JSONWrapperController> wrapper {get;set;}

    public void deserialize() {

        try{
            string jsonresponse = '[{ "caPerformanceRecordList": [ {  "submissionCount": 2 }, {  "submissionCount": 5 } ], "ecPerformanceRecordList": [ {   } ] }]';

           
            wrapper = (list<JSONWrapperController>) JSON.deserialize(jsonresponse, list<JSONWrapperController>.class);

            
        } catch (Exception e){
            system.debug('Error---->' +  e.getLineNumber() + e.getMessage());

        }
    }


---------------------------------------------

public class JSONWrapperController {

	public List < CaPerformanceRecordList > caPerformanceRecordList{get;set;}


	public class CaPerformanceRecordList {
	  public String motorDealerID{get;set;}
	  public String dealerName{get;set;}
	  public String reportingPeriod{get;set;}
      public String   financeSourceIntegrationTypeCode{get;set;}
	  public String idlPlus{get;set;}
	  public String creditApplicationSourceCode{get;set;}
	}
	
	@AuraEnabled
         public integer getTotalAppCount() {
              // loop through each element in the     caPerformanceRecordList, till the end of the list.
             // get grand total of submissionCount 
             // return grand total  
        
             integer appTotal = 0;
             for(CaPerformanceRecordList cp : caPerformanceRecordList) {
                 appTotal += cp.submissionCount;
              }
              return appTotal;
         }

}

 
Best Answer chosen by RarLopz
Deepali KulshresthaDeepali Kulshrestha
Hi RarLopz,

- I read your problem and implemented it in my Org and it is working fine.
- Please use the below code [Solved] : -
--------------VF Page------------------
 
<apex:page controller="CASReportController">
    <apex:form >
        <apex:pageBlock title="JSON Deserialized Response">
            <apex:pageBlockButtons >
                <apex:commandButton value="submit" action="{!deserialize}" reRender="DealerBlock"/>
            </apex:pageBlockButtons>


            <apex:pageBlockSection id="DealerBlock" columns="1">
                <apex:repeat value="{!wrapper}" var="cap1">

                    <apex:pageBlockTable value="{!cap1.caPerformanceRecordList}" var="cap" width="100%">

                        <apex:column headerValue="Reporting Period" value="{!cap.reportingPeriod}"/>

                        <apex:column headerValue="FS Integration Type Code" value="{!cap.financeSourceIntegrationTypeCode}"/>

                        <apex:column headerValue="IDL Plus" value="{!cap.idlPlus}"/>

                        <apex:column headerValue="Credit Application Source Code" value="{!cap.creditApplicationSourceCode}"/>

                        <apex:column headerValue="Submission Count" value="{!cap.submissionCount}" />


                        <!-- Generating CASubmissionCount total -->



                        <!--footer of the SubmissionCount -->
                        <apex:facet name="footer">
                            Total Count: <span class="t1" style="pading-left:20px"> </span>   {!cap1.appTotal}               <b><!--  expecting Total Count = 7 --    submissionCount of one record is 2 and other record is 7 as seen in json string -->    </b>
                        </apex:facet>

                    </apex:pageBlockTable>
                </apex:repeat>

            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

-------------- Apex Controller------- -----
public with sharing class CASReportController {
    @AuraEnabled
    public list<JSONWrapperController> wrapper {get;set;}

    public void deserialize() {

        try{
            string jsonresponse = '[{ "caPerformanceRecordList": [ { "motorDealerID": "XL1HX", "dealerName": "Subaru Auto Dealer", "reportingPeriod": "2019-05-18", "financeSourceIntegrationTypeCode": "FIFS", "idlPlus": "Y", "creditApplicationSourceCode": "STEONE", "submissionCount": 2 }, { "motorDealerID": "XL1HX", "dealerName": "Subaru Auto Dealer", "reportingPeriod": "2019-06-27", "financeSourceIntegrationTypeCode": "FIFS", "idlPlus": "Y", "creditApplicationSourceCode": "STEONE", "submissionCount": 5 } ], "ecPerformanceRecordList": [ { "motorDealerID": "XL1HX", "submitUserID": "BCUSER1", "bookedDate": "2019-05-22 00:00:00.0", "ecEligible": "Y", "caBookedCount": 1, "ecBookedCount": 0 }, { "motorDealerID": "XL1HX", "submitUserID": "BCUSER1", "bookedDate": "2019-06-05 00:00:00.0", "ecEligible": "Y", "caBookedCount": 1, "ecBookedCount": 0 } ] }]';

            system.debug('json string is ' +jsonresponse);
            wrapper = (list<JSONWrapperController>) JSON.deserialize(jsonresponse, list<JSONWrapperController>.class);

            getTotalAppCount(wrapper);
            system.debug('This is the wrapper class: ' +wrapper);
        } catch (Exception e){
            system.debug('Error---->' +  e.getLineNumber() + e.getMessage());

        }
    }


    public void getTotalAppCount(list<JSONWrapperController> wrapper) {
        // loop through each element in the     caPerformanceRecordList, till the end of the list.
        // get grand total of submissionCount
        // return grand total


        for(JSONWrapperController jw: wrapper){
            jw.appTotal=0;
            for (CaPerformanceRecordList cp : jw.caPerformanceRecordList) {
                jw.appTotal += cp.submissionCount;
            }
        }

    }


public class JSONWrapperController {

public List < CaPerformanceRecordList > caPerformanceRecordList{
get;set;
}
public List < EcPerformanceRecordList > ecPerformanceRecordList{
get;set;
}
    public  integer appTotal{get;set;}

}
public class EcPerformanceRecordList {
public String motorDealerID{get;set;}
public String submitUserID{get;set;}
public String bookedDate{get;set;}
public String ecEligible{get;set;}
public Integer caBookedCount{get;set;}
public Integer ecBookedCount{get;set;}
}



public class CaPerformanceRecordList {
public String motorDealerID{get;set;}
public String dealerName{get;set;}
public String reportingPeriod{get;set;}
public String financeSourceIntegrationTypeCode{get;set;}
public String idlPlus{get;set;}
public String creditApplicationSourceCode{get;set;}
    public Integer submissionCount{get;set;}

}

}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.

All Answers

Deepali KulshresthaDeepali Kulshrestha
Hi RarLopz,

- I read your problem and implemented it in my Org and it is working fine.
- Please use the below code [Solved] : -
--------------VF Page------------------
 
<apex:page controller="CASReportController">
    <apex:form >
        <apex:pageBlock title="JSON Deserialized Response">
            <apex:pageBlockButtons >
                <apex:commandButton value="submit" action="{!deserialize}" reRender="DealerBlock"/>
            </apex:pageBlockButtons>


            <apex:pageBlockSection id="DealerBlock" columns="1">
                <apex:repeat value="{!wrapper}" var="cap1">

                    <apex:pageBlockTable value="{!cap1.caPerformanceRecordList}" var="cap" width="100%">

                        <apex:column headerValue="Reporting Period" value="{!cap.reportingPeriod}"/>

                        <apex:column headerValue="FS Integration Type Code" value="{!cap.financeSourceIntegrationTypeCode}"/>

                        <apex:column headerValue="IDL Plus" value="{!cap.idlPlus}"/>

                        <apex:column headerValue="Credit Application Source Code" value="{!cap.creditApplicationSourceCode}"/>

                        <apex:column headerValue="Submission Count" value="{!cap.submissionCount}" />


                        <!-- Generating CASubmissionCount total -->



                        <!--footer of the SubmissionCount -->
                        <apex:facet name="footer">
                            Total Count: <span class="t1" style="pading-left:20px"> </span>   {!cap1.appTotal}               <b><!--  expecting Total Count = 7 --    submissionCount of one record is 2 and other record is 7 as seen in json string -->    </b>
                        </apex:facet>

                    </apex:pageBlockTable>
                </apex:repeat>

            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

-------------- Apex Controller------- -----
public with sharing class CASReportController {
    @AuraEnabled
    public list<JSONWrapperController> wrapper {get;set;}

    public void deserialize() {

        try{
            string jsonresponse = '[{ "caPerformanceRecordList": [ { "motorDealerID": "XL1HX", "dealerName": "Subaru Auto Dealer", "reportingPeriod": "2019-05-18", "financeSourceIntegrationTypeCode": "FIFS", "idlPlus": "Y", "creditApplicationSourceCode": "STEONE", "submissionCount": 2 }, { "motorDealerID": "XL1HX", "dealerName": "Subaru Auto Dealer", "reportingPeriod": "2019-06-27", "financeSourceIntegrationTypeCode": "FIFS", "idlPlus": "Y", "creditApplicationSourceCode": "STEONE", "submissionCount": 5 } ], "ecPerformanceRecordList": [ { "motorDealerID": "XL1HX", "submitUserID": "BCUSER1", "bookedDate": "2019-05-22 00:00:00.0", "ecEligible": "Y", "caBookedCount": 1, "ecBookedCount": 0 }, { "motorDealerID": "XL1HX", "submitUserID": "BCUSER1", "bookedDate": "2019-06-05 00:00:00.0", "ecEligible": "Y", "caBookedCount": 1, "ecBookedCount": 0 } ] }]';

            system.debug('json string is ' +jsonresponse);
            wrapper = (list<JSONWrapperController>) JSON.deserialize(jsonresponse, list<JSONWrapperController>.class);

            getTotalAppCount(wrapper);
            system.debug('This is the wrapper class: ' +wrapper);
        } catch (Exception e){
            system.debug('Error---->' +  e.getLineNumber() + e.getMessage());

        }
    }


    public void getTotalAppCount(list<JSONWrapperController> wrapper) {
        // loop through each element in the     caPerformanceRecordList, till the end of the list.
        // get grand total of submissionCount
        // return grand total


        for(JSONWrapperController jw: wrapper){
            jw.appTotal=0;
            for (CaPerformanceRecordList cp : jw.caPerformanceRecordList) {
                jw.appTotal += cp.submissionCount;
            }
        }

    }


public class JSONWrapperController {

public List < CaPerformanceRecordList > caPerformanceRecordList{
get;set;
}
public List < EcPerformanceRecordList > ecPerformanceRecordList{
get;set;
}
    public  integer appTotal{get;set;}

}
public class EcPerformanceRecordList {
public String motorDealerID{get;set;}
public String submitUserID{get;set;}
public String bookedDate{get;set;}
public String ecEligible{get;set;}
public Integer caBookedCount{get;set;}
public Integer ecBookedCount{get;set;}
}



public class CaPerformanceRecordList {
public String motorDealerID{get;set;}
public String dealerName{get;set;}
public String reportingPeriod{get;set;}
public String financeSourceIntegrationTypeCode{get;set;}
public String idlPlus{get;set;}
public String creditApplicationSourceCode{get;set;}
    public Integer submissionCount{get;set;}

}

}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
This was selected as the best answer
RarLopzRarLopz
Thanks @DeepaliKulshrestha

I am getting an error at the following lines
for(JSONWrapperController jw: wrapper){
            jw.appTotal=0;
            for (CaPerformanceRecordList cp : jw.caPerformanceRecordList) {
                jw.appTotal += cp.submissionCount;
            }
        }

User-added image

Also i notice a strange thing in the debug after the JSON String is deserialized and cast to the Wrapper class. 
Notice how, it is incomplete. 

USER_DEBUG [19]|DEBUG|This is the wrapper class: 

(JSONWrapperController:[appTotal=null, caPerformanceRecordList=
(CaPerformanceRecordList:[creditApplicationSourceCode=STEONE, dealerName=Subaru Auto Dealer, financeSourceIntegrationTypeCode=FIFS, idlPlus=Y, reportingPeriod=2019-05-18, motorDealerID=XL1HX, submissionCount=2],
CaPerformanceRecordList:[creditApplicationSourceCode=RTEONE, dealerName=Subaru Auto Dealer, financeSourceIntegrationTypeCode=FIFS, idlPlus=Y, reportingPeriod=2019-06-27, motorDealerID=XL1HX, submission 


Is my deserailizing technique incorrect/ am i not creating an incoorect data structure for the wrapper class? 

Thank you. 
RarLopzRarLopz
Ignore the second part of my question where I mention about seeeing only half of the, debug log. 
I see the  entire log when i open raw logs. 

However I am still struggling with the first part of the question, error about InvalidType
RarLopzRarLopz
Ok so i was able to get past this errro. The change i made is this .. 
 
for (JSONWrapperController.CaPerformanceRecordList cp : jw.caPerformanceRecordList) {
                jw.appTotal += cp.submissionCount;

}