+ Start a Discussion
Vijay Zutshi 2Vijay Zutshi 2 

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

Hi,

I want to display related contacts of an Account using Visualforce page for which my Apex Page and Apex Class is listed below.

My Apex page is:

<apex:page controller="DisplayRelatedContactAccount" sidebar="false">
    <apex:form >        
        <apex:pageBlock >
            <apex:pageBlockSection > 
                <apex:outputText value="Enter Account Name">                    
                </apex:outputText>                
                <apex:inputText value="{! acctName}"/> 
                <apex:commandButton value="Show Contacts" action="{! showContacts}" reRender="out" status="mystatus"/>
                <apex:actionStatus id="mystatus" startText="Please wait related account contacts are loading....">
                </apex:actionStatus>
                <apex:pageBlockTable value="{! Contacts}" var="ct" rendered="{! acctName !=Null}">                
                    <apex:column headerValue="Name">
                        {! ct.Name}
                    </apex:column>
                    <apex:column headerValue="Phone">
                        {! ct.Phone}
                    </apex:column>
                    <apex:column headerValue="Email">
                        {! ct.Email}
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

For this my Apex class is :

public class DisplayRelatedContactAccount {
    public string acctName {get; set;}
    SET<string> accIds = new SET<string>();
    //public List<Contact> Contacts {get; set;}
    List<Account> lstacc = new List<Account>();
    List<contact> lstcon = new List<contact>();
    public List<Contact> showContacts(){
        lstacc = [SELECT Id, Name
                  FROM Account
                  WHERE name =:acctName];
        for(integer i=0; i<lstacc.size(); i++) {
            accIds.add(lstacc[i].id);
        }
        lstcon = [SELECT Id, Name, Phone, Email, AccountId
                  FROM Contact
                  WHERE AccountId IN :accIds];
        return lstcon;        
    }    
    public Pagereference showContacts() {
        return null;
    }
}

I am getting following error msg :

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

Please advise what needs to be done to remove the above mentioned error msg.

Thanks
Vijay Zutshi
VinayVinay (Salesforce Developers) 
Hi Vijay,

Check below examples for details on above error message.

https://salesforceglobe4u.blogspot.com/2015/07/return-type-of-apex-action-method-must.html
https://salesforce.stackexchange.com/questions/121711/how-to-solve-this-error-return-type-of-an-apex-action-method-must-be-a-pagerefe

Thanks,