0

I'm trying to display my deserialized JSON on my VF page but I get Unknown property 'PDSrestCall.userProfile.ibmUniqueId' Help Please.

PS i removed the API endpoint for security purposes.

Here is my code:

global with sharing class PDSrestCall {

    public String requestMethod {get;set;}
    public String requestEndpoint {get;set;}
    public String responseStatus {get;set;}
    public Integer responseStatusCode {get;set;}
    public String responseBody {get;set;}
    public List<userProfile> userDetails {get;set;} 



    global static void restCall() {
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('');
        req.setMethod('GET');
        req.setHeader('Content-Type', 'application/json');

       HTTPResponse res = http.send(req);

       userProfile u = (userProfile)JSON.deserialize(res.getBody(),userProfile.class);

       system.debug('ibmUniqueId: ' + u.ibmUniqueId);
       system.debug('ibmId: ' + u.ibmId);
       system.debug('userName: ' + u.userName);
       system.debug('firstName: ' + u.firstName);
       system.debug('lastName: ' + u.lastName);
       system.debug('email: ' + u.email);
       system.debug('phone: ' + u.phone);
    }

   public List<SelectOption> getMethodOptions(){
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('GET','GET'));
        options.add(new SelectOption('POST','GET'));
        options.add(new SelectOption('PUT','GET'));
        options.add(new SelectOption('DELETE','GET'));
        options.add(new SelectOption('HEAD','GET'));
        return options;
    }


    global class userProfile{
        public String ibmUniqueId;
        public String ibmId;
        public String userName;
        public String firstName;
        public String lastName;
        public String email;
        public String phone;


        public userProfile(String ibmUniqueId, String ibmId, String userName, String firstName, String lastName, String email, String phone) {
            this.ibmUniqueId = ibmUniqueId;
            this.ibmId = ibmId;
            this.userName = userName;
            this.firstName = firstName;
            this.lastName = lastName;
            this.email = email;
            this.phone = phone;
        }
    }
}

Here is my VF code:

<apex:page id="page" controller="PDSrestCall" >
    <apex:form id="form" >
        <apex:sectionHeader title="RESTFUL Callout Viewer" />
        <apex:pageMessages id="pageMessages" />
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Callout and Deserialize" action="{!restCall}" rendered="{!$CurrentPage.parameters.offline!='1'}"/>
            <!--       <apex:commandButton value="Deserialize" action="{!getDeserializeProfileDataService}" rendered="{!$CurrentPage.parameters.offline!='1'}"/> -->

                <apex:commandButton value="Callout and Deserialize  (offline)" action="{!restCall}" rendered="{!$CurrentPage.parameters.offline=='1'}" />
            <!--     <apex:commandButton value="Deserialize (offline)" action="{!getDeserializeProfileDataService}" rendered="{!$CurrentPage.parameters.offline=='1'}" /> -->

            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1" title="HttpRequest" collapsible="false" >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="setMethod()" />
                <!--    <apex:selectList size="1" value="{!requestMethod}" > 
                        <apex:selectOptions value="{!MethodOptions}" />
                    </apex:selectList>  -->
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                 <!--   <apex:outputLabel value="setEndpoint()" />
                    <apex:inputText value="{!setEndpoint}" style="width:90%" /> -->
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <apex:pageBlockSection columns="1" title="HttpResponse" collapsible="false" >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="getStatusCode()" />
                    <apex:outputText value="{!responseStatusCode}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="getStatus()" />
                    <apex:outputText value="{!responseStatus}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="getBody()" />

                    {!responseBody}
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

            <apex:pageBlockSection columns="1" title="JSON Deserializer"  collapsible="false" >
                <apex:pageBlockTable value="{!userDetails}" var="i" >
                    <!-- <apex:column headerValue="Owner" style="width:100px;" >
                        <apex:outputLink value="{!i.owner.link}" target="_blank" style="width:100px;" >
                            <apex:image value="{!i.owner.profile_image}" alt="{!i.owner.display_name}" style="height:30%; width:30%;" /><br/>{!i.owner.display_name}
                        </apex:outputLink>
                    </apex:column> -->
                    <apex:column headerValue="ibmUniqueId" style="width:75px;" >
                        <apex:outputText value="{!i.ibmUniqueId}" />
                    </apex:column>
                    <apex:column headerValue="ibmId" style="width:75px;" >
                        <apex:outputText value="{!i.ibmId}" />
                    </apex:column>
                    <apex:column headerValue="userName" style="width:75px;" >
                        <apex:outputText value="{!i.userName}" />
                    </apex:column>
                    <apex:column headerValue="firstName" style="width:75px;" >
                        <apex:outputText value="{!i.firstName}" />
                    </apex:column>
                    <apex:column headerValue="lastName" style="width:50px;" >
                        <apex:outputText value="{!i.lastName}" />
                    </apex:column>
                    <apex:column headerValue="email" >
                        <apex:outputText value="{!i.email}" />
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
2

Notice how your controller has attributes annotated with getters and setters:

public String requestMethod {get;set;}

You need to do the same for your class definition. Note that you should use private setters unless you actually want the page to sat an attribute, and you should not use getters or setters for variables you do not need to reference on your page.

global class userProfile{
    public String ibmUniqueId { get; private set; }
    public String ibmId { get; private set; }
    // and so on
}

See also:

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.