0

I deleted the previous code that I had on this post.

I modified my code again:

Now I am getting this error If I press the Search Button from VF page:

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

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;   
}    

}


<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>


2
  • Its just a wrapper class to return results. But there should be a method or a separate class that call your wrapper.
    – Anurag
    May 18, 2017 at 17:47
  • Should I add class like public PageReference searchPatients(){ return; } and modify on Visualforce page like action="{!searchPatients}" ? Sorry. I am not sure how to express to call the wrapper properly.
    – Java
    May 18, 2017 at 18:01

2 Answers 2

3

Currently you have search logic in constructor "WrapperDemoController2". It loads everytime the page loads. You dont need to specify action.

But if you want this logic to run everytime when button is clicked, move that logic to a new method like follows,

public List<TableRow2> searchResults(){

    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;
}

VF Page:

<apex:commandButton value="Search" action="{!searchResults}" reRender="contact-table"/>
7
  • I am still having difficulty understanding your feedback. So, do I need to leave current constructor "WrapperDemoController2" and add the new method on the bottom?
    – Java
    May 18, 2017 at 19:58
  • Please use the method from my answer. The method should have a return type of List<TableRow2> not pagereference.
    – Anurag
    May 18, 2017 at 21:30
  • I modified the code, but now it is showing me Compile Error: Missing return statement required return type Listat line 15: This is line 15: public List < TableRow2 > searchPatients(){
    – Java
    May 18, 2017 at 22:58
  • You can refer to the updated code from my answer. Add return RowList; before the method closes.
    – Anurag
    May 19, 2017 at 13:46
  • Hi Anurag, thanks for help again. And Thanks Jagmohan for updating my text. I updated my code shown on the top. I am getting this error now. "Return type of an Apex action method must be a PageReference. Found: core.apexpages.el.adapters.ApexListELAdapter"
    – Java
    May 19, 2017 at 14:34
1

I got the solutions (two changes) : I needed to change from: public List searchPatients() to: public PageReference searchPatients()

And return statment must be set to null Changed from: return RowList; to: return null;

You must log in to answer this question.

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