I am calling the REST GET method and trying to display the result of the REST call in Visualforce page. I developed the code so far but facing small error.

Unknown property 'ApexRestController.cases'

It would be better to display result on page load only. How ?

When I tried using Postman I got the following response which I want to show to client using Visualforce page.

"Subject":"Bigfoot Sighting!",

The code I developed so far:


public class CaseDetails {
    public String CaseNumber {get; set;}
    public String Subject {get; set;}
    public String Status {get; set;}
    public String Priority {get; set;}
    public String Id {get; set;}


<apex:page controller="ApexRestController">
    <apex:form >
        <apex:pageBlock >
            <apex:commandButton reRender="table1" value="Get Case Details" action="{!getCaseDetailsById}"/>

        <apex:pageBlock id="table1">
            <b>Output Contact Details </b>
            <apex:pageBlockTable value="{!cases}" var="c">
                <apex:column headerValue="CaseNumber" value="{!c.CaseNumber}" />
                <apex:column headerValue="Subject" value="{!c.Subject}" />
                <apex:column headerValue="Status" value="{!c.Status}" />


public class ApexRestController {
    public static List<CaseDetails> cases {get; set;}

    public static String getAccessToken(){
        HttpRequest req = new HttpRequest();

        String CLIENT_ID = 'XXXXX';
        String CLIENT_SECRET = 'XXX';
        String USERNAME = 'XXX';
        String PASSWORD = 'XX';

        req.setBody('grant_type=password' + '&client_id='+CLIENT_ID + 
            '&client_secret='+CLIENT_SECRET + '&username='+USERNAME + '&password='+PASSWORD);

        Http http = new Http();
        HTTPResponse res = http.send(req);

        String access_token = res.getBody();
        List<String> access_tokenList = new List<String>();
        access_tokenList  = access_token.split(',',-1);
        access_tokenList  = access_tokenlist[0].split(':',-1);
        String tokennew = access_tokenList[1].replace('"','');
        return tokennew;

    public static CaseDetails getCaseDetailsById(){
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setHeader('Authorization', 'Bearer '+getAccessToken());

        HTTPResponse res = http.send(req);

        cases = (List<CaseDetails>) JSON.deserialize(res.getBody(), List<CaseDetails>.class);
        return cases[0];

The issue is you have declared the variable as static

public static List<CaseDetails> cases {get; set;}

And you are trying to access that from

<apex:pageBlockTable value="{!cases}" var="c">

That's the reason it is giving Unknown property 'ApexRestController.cases' error.

Correct usage

public List<CaseDetails> cases {get; set;}

Static variables are not serialized (as if you'd used the "transient" keyword), meaning they will be "lost" between each trip back to the server. I would recommend removing all of the static keywords in your code. None of them are necessary for your code to function.

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.