function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Justin DJustin D 

Visualforce Error: Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.adapters.ApexListELAdapter

Hi Everyone,
I am trying to figure out how to resolve this error. Any feedback is appereciated.

Visualforce Error: Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.adapters.ApexListELAdapter
-------------------------------------

Bottom is my VF markup:
-------------------------------------
<apex:page Controller="WrapperDemoController2">
<apex:form >
    <apex:pageBlock >
        <!-- Serarch button-->
        <apex:pageBlockButtons location="top">
            <apex:commandButton value="Search" action="{!searchPatients}" reRender="contact-table"/>
         </apex:pageBlockButtons>
                
        <apex:pageBlockSection id="contact-table" columns="1">
            <!-- Input -->
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="MRN" />
                <apex:inputText value="{!mrn}"/>
            
            </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
    
            <!-- Output --->
            <apex:pageBlockTable value="{!RowList}" var="c">
                <apex:column value="{!c.mrn}"/>
                <apex:column value="{!c.sfprn}"/>
                <apex:column value="{!c.SurveySelection}"/>
            </apex:pageBlockTable>   
    </apex:pageBlock>
</apex:form>    
</apex:page>
------------------------------------------
Bottom is Apex code:
------------------------------------------
public class WrapperDemoController2{
   
    public String sfprn { get; set; }
    public String searchPatients { get; set; }
    public String mrn {get;set;}
    
    public class TableRow2{
        public String sfprn {get;set;}
        public String mrn {get;set;}
        public Decimal SurveySelection {get;set;}
    }
   
    public List<TableRow2> RowList {get; set;}

    public List<TableRow2> searchPatients(){

        RowList = new List<TableRow2>();
        TableRow2 tr;

        for(Patient__c con : [SELECT sfprn__c, 
                                    mrn__c, 
                                    (select SurveySelection__c.SurveySelection__c from SurveySelections__r) 
                                    FROM Patient__c
                                    where mrn__c =:mrn                                    
                                    ]){
                                 
            tr = new TableRow2();
            tr.sfprn = con.sfprn__c;
            tr.mrn = con.mrn__c;
            tr.SurveySelection = con.SurveySelections__r.isEmpty() ? null : con.SurveySelections__r[0].SurveySelection__c;
            
            RowList.add(tr);
            }
         return RowList;   
    }    
}
 
Best Answer chosen by Justin D
Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Justin,

Your code looks fine but all Action methods in a Visualforce Controller must return a PageReference. So you just have to change your action method signature from:
 
public List<TableRow2> searchPatients()

To
 
public PageReference searchPatients()

And your return statment must be set to null
 
return null;

Read more about in:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_system_pagereference.htm

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.

All Answers

Zuinglio Lopes Ribeiro JúniorZuinglio Lopes Ribeiro Júnior
Hello Justin,

Your code looks fine but all Action methods in a Visualforce Controller must return a PageReference. So you just have to change your action method signature from:
 
public List<TableRow2> searchPatients()

To
 
public PageReference searchPatients()

And your return statment must be set to null
 
return null;

Read more about in:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_system_pagereference.htm

Hope to have helped!

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
This was selected as the best answer
Justin DJustin D
Thanks Zuinglio.