0

What is it I am doing to get the invalid type error?

    public with sharing class MyController {

        public list<JSONWrapper> wrapper {get;set;}
        public integer appTotal{get;set;}   

        public void getDeserialize() {

        string jsonresponse = '[{"appList":[{"dealerID":"ABC123","dealerName":"ABC Auto Dealer",                    "reportingPeriod":"2019-05-                 18","fsitCode":"FIFS","idl":"Y","casCode":"STEONE","submissionCount":2},{"dealerID":                    "ABC123","dealerName":"ABC Auto Dealer","reportingPeriod":"2019-06-27","fsitCode":"FIFS","idl":"Y",                     "casCode":"STEONE","submissionCount":5}],"eclist":                  [{"dealerID":"XL1HX","submitUserID":"BCUSER1","bookedDate":"2019-05-22                  00:00:00.0","ecEligible":"Y","caBookedCount":1,"ecBookedCount":0},{"dealerID":"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<JSONWrapper>) JSON.deserialize(jsonresponse, list<JSONWrapper>.class);

            system.debug('This is the wrapper' +wrapper);

        }

        public integer getTotalAppCount(list<JSONWrapper> wrapper) {

        // loop through each element in the appList, till the end of the list.
        // get grand total of submissionCount
        // return grand total

            for(JSONWrapper jw: wrapper){
                jw.appTotal=0;

                // Error is here
                for (ApplicationList cp : jw.appList) {
                  jw.appTotal += cp.submissionCount;
                }
            }

            return appTotal;
        }

}




public class JSONWrapper {

    public List<ApplicationList> appList{get;set;}
    public List<ElectronicContractList> eclist {get;set;}
    public integer appTotal {get;set;} 

    public class ElectronicContractList{
        public String  dealerID{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 ApplicationList {
        public String dealerID{get;set;}
        public String dealerName{get;set;}
        public String reportingPeriod{get;set;}
        public String fsitCode{get;set;}
        public String idl{get;set;}
        public String casCode{get;set;}
        public Integer submissionCount{get;set;}
    }
}

Error: Invalid Type:ApplicationList

4

ApplicationList is an inner class of JSONWrapper. References to that class outside of the JSONWrapper class itself, where it's in scope, must qualify the name with its outer class: JSONWrapper.ApplicationList. Hence,

for (JSONWrapper.ApplicationList cp : jw.appList) {

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.