I have the following code which gives me below error.

Return type of an Apex action method must be a PageReference. Found: visualforce.el.VisualforceArrayList

The VF Page I developed.

<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="{!caList}" var="ca">
                <apex:column headerValue="CaseNumber" value="{!ca.CaseNumber}" />
                <apex:column headerValue="Subject" value="{!ca.Subject}" />
                <apex:column headerValue="Status" value="{!ca.Status}" />


And Controller class

public class ApexRestController {
    public List<Case> caList {get; set;}

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

        String CLIENT_ID = 'XX';
        String CLIENT_SECRET = 'XX';
        String USERNAME = 'XX';
        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();
        return access_token;

    public List<Case> getCaseDetailsById(){
        Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setHeader('Authorization', 'Bearer '+getAccessToken());

        HTTPResponse res = http.send(req);
        String json = res.getBody();

        Case ca = (Case) System.JSON.deserialize(json, Case.class);
        caList = new List<Case>();
        return caList;

2 Answers 2


Your getCaseDetailsById() should not be returning List instead it should be returning PageReference (or) Void

  • Hey Thnx working, what PageReference is only working ? May 15, 2017 at 19:06
  • Sorry , can you please explain , i am not able to get it .
    – freaker87
    May 15, 2017 at 19:10
  • Why PageReference method es expected to the salesforce? Why List<> does not get worked ? May 15, 2017 at 19:15
  • 1
    When action method is invoked the system invokes a GET / POST method . When you do a GET/POST method it implicitly means that the system will do a request -response . When the response comes back it may in various format xml,html,xhtml ,xhr anything which the browser has to render visually. This is one part to it . But on the other hand salesforce as a system will try to redirect you to some page after action has been performed and the data type it looks is only PageReference / void - If it solves your query mark it so that people will know that this solution may work for them - THanks
    – freaker87
    May 15, 2017 at 19:20

If you change the return type of your getCaseDetailsById method to PageReference, update caList and return null from the method, the page will post back with the updates to caList.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .