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 

JSON2Apex

 json response 
{
    "caPerformanceRecordList": [
       
        {
            "sourceOneDealerID": "XL1HX",
            "dealerName": "Superior Auto Dealer",
            "reportingPeriod": "2019-06-25",
            "financeSourceIntegrationTypeCode": "FIFS",
            "independentdlrPlus": "Y",
            "caApplicationSourceCode": "ECKNWNSPT",
            "submissionCount": 1
        },
        
        {
            "sourceOneDealerID": "XL1HX",
            "dealerName": "Superior Auto Dealer",
            "reportingPeriod": "2019-06-25",
            "financeSourceIntegrationTypeCode": "PIFS",
            "independentdlrPlus": "Y",
            "caApplicationSourceCode": "RTEONE",
            "submissionCount": 1
        },
        {
            "sourceOneDealerID": "XL1HX",
            "dealerName": "Superior Auto Dealer",
            "reportingPeriod": "2019-06-26",
            "financeSourceIntegrationTypeCode": "FIFS",
            "independentdlrPlus": "Y",
            "caApplicationSourceCode": "RTEONE",
            "submissionCount": 15
        }
    ],
    "ecPerformanceRecordList": [
        {
            "sourceOneDealerID": "XL1HX",
            "submitUserID": "ECUSER1",
            "bookedDate": "2019-05-22 00:00:00.0",
            "ecEligible": "Y",
            "caBookedCount": 1,
            "ecBookedCount": 0
        },
        {
            "sourceOneDealerID": "XL1HX",
            "submitUserID": "ECUSER1",
            "bookedDate": "2019-06-05 00:00:00.0",
            "ecEligible": "Y",
            "caBookedCount": 1,
            "ecBookedCount": 0
        }
    ]
}

Using Json2Apex I got this class, 
 
public class JSON2ApexWrapper {

	public class EcPerformanceRecordList {
		public String sourceOneDealerID;
		public String submitUserID;
		public String bookedDate;
		public String ecEligible;
		public Integer caBookedCount;
		public Integer ecBookedCount;
	}

	public class CaPerformanceRecordList {
		public String sourceOneDealerID;
		public String dealerName;
		public String reportingPeriod;
		public String financeSourceIntegrationTypeCode;
		public String independentdlrPlus;
		public String caApplicationSourceCode;
		public Integer submissionCount;
	}

	public List<CaPerformanceRecordList> caPerformanceRecordList;
	public List<EcPerformanceRecordList> ecPerformanceRecordList;

	
	public static JSON2ApexWrapper parse(String json) {
               return (JSON2ApexWrapper) System.JSON.deserialize(json,JSON2ApexWrapper.class);
	}
}
 I want to create a Visualforce page to display a table adds the submissionCount for each day in the list and dislays the total 

e.g   caPerformanceRecordList   MonthtoDate(SubmittedCount) = 17 
       ecPerformanceRecordList:
       MonthtoDate(Total: caBookedCount) =  2
       MonthtoDate(Total: ecBookedCount) = 0

What do i need to change in the wrapper class to be able to calculate these sums and then reference in visualforce page ? 

Thanks you . 
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] : -
 
------------- 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.