0

Another day, another error.

I'm getting the following error from VisualForce when accessing the data in my wrapper class:

Unknown property 'VisualforceArrayList.terrByCountList' Error is in expression '{!wrapper.terrByCountList}' in component in page hapi_testindex

I'm trying to call the data from my wrapper class to populate tables, on my VF page.

Here is my code:

Callout Class

public class HAPI_callOut {

    public List<HAPI_TerrByCount_wrapper> wrapper {get; set;}

    public void deserialize() {

        HttpRequest request = new HttpRequest();

        request.setEndpoint('callout:HAPI_CallOut/territories-by-country/US');
        request.setMethod('GET');
        request.setTimeout(120000);

        Http service = new Http();
        HttpResponse response = service.send(request);

        wrapper = (List<HAPI_TerrByCount_wrapper>)JSON.deserialize(response.getBody(), List<HAPI_TerrByCount_wrapper>.class);
    }
}

Wrapper Class

public class HAPI_TerrByCount_wrapper {

    public class TerritoriesByCountry {
        public String territoryId {get; set;}
        public String territoryName {get; set;}
        public String startDate {get; set;}
        public String endDate {get; set;}
        public Integer recordIndex {get; set;}
    }

    public List<TerritoriesByCountry> terrByCountList {get; set;}

}

VisualForce Page

<apex:page controller="HAPI_callOut">
<apex:form >
    <apex:pageBlock title="Alignment Territories By Country Data">
        <apex:pageBlockButtons >
            <apex:commandButton value="Get Data!" action="{!deserialize}" reRender="TerrByCountBlock"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection id="TerrByCountBlock" columns="1">
            <apex:repeat value="{!wrapper.terrByCountList}" var="territory">
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Territory Name" for="territoryName" />
                        <apex:outputText value="{!territory.territoryName}" id="territoryName" />
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Start Date" for="startDate" />
                        <apex:outputText value="{!territory.startDate}" id="startDate" />
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="End Date" for="endDate" />
                        <apex:outputText value="{!territory.endDate}" id="endDate" />
                    </apex:pageBlockSectionItem>
            </apex:repeat>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>

Any help would be greatly appreciated because I can't get to the bottom of this.

Thank you!

4

Your wrapper object class is TerritoriesByCountry, so your controller should instantiate a list of these objects and deserialize into it. There's no need to maintain another list of objects within the wrapper class itself.

Change your controller to reference the wrapper object directly:

public class HAPI_callOut {

    public List<HAPI_TerrByCount_wrapper.TerritoriesByCountry> wrapper {get; set;}

    public void deserialize() {
            [your other code]

        wrapper = (List<HAPI_TerrByCount_wrapper.TerritoriesByCountry>)JSON.deserialize(response.getBody(), List<HAPI_TerrByCount_wrapper.TerritoriesByCountry>.class);
    }
}

Change the repeat line in your Visualforce page:

<apex:repeat value="{!wrapper}" var="territory">

And remove the unnecessary list in your wrapper class:

public class HAPI_TerrByCount_wrapper {
    public class TerritoriesByCountry {
        public String territoryId {get; set;}
        public String territoryName {get; set;}
        public String startDate {get; set;}
        public String endDate {get; set;}
        public Integer recordIndex {get; set;}
    }
}
  • When I applied your changes, I got the following error: Error: Unknown property 'HAPI_TerrByCount_wrapper.territoryId' – Adil Khan Mar 19 '18 at 15:56
  • Sorry, see my edited answer. – David Cheng Mar 19 '18 at 16:13

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.