[SalesForce] How to solve this error “Return type of an Apex action method must be a PageReference. Found: visualforce.el.VisualforceArrayList “

Basically I have custom button in datail page .When i click this button,I have four picklist and checkbox in VF.I have to click atleast one picklist one checkbox .After clicking save button some records are returned based on the selection and redirect to the detail page with inserted records.When i run this in IE ,the Page is Working fine !! but when i try to run this code in Chrome and Mozila am getting error as

"Return type of an Apex action method must be a PageReference. Found: visualforce.el.VisualforceArrayList ".After choosing the picklist value ,the error was shown.

How to solve this !!

VF

<apex:page standardController="Rfleet_Car_Set__c" extensions="Rfleet_AdditionalServices_CLS" >
<apex:form >
<apex:pageMessages >
</apex:pageMessages>
<apex:pageBlock >

     <apex:pageblockbuttons location="bottom" >

        <apex:commandbutton value="Save" action="{!saveService}" /> 
         <apex:commandbutton value="Cancel" action="{!cancel}" />

    </apex:pageblockbuttons>


    <apex:pageblocksection columns="1" >

        <apex:pageblocksectionitem >
        <apex:outputLabel >Carset</apex:outputLabel>
        <apex:selectList size="1"  value="{!strCarsetOption}" >
        <apex:selectOptions value="{!Options }" > </apex:selectOptions>
        <apex:actionSupport event="onchange" action="{!retrieveService}" reRender="a"/>
        </apex:selectList> 
        </apex:pageblocksectionitem>

        <apex:pageblocksectionitem >
         <apex:outputLabel > Network services</apex:outputLabel>
         <apex:inputCheckbox value="{!strNWservice}"> <apex:actionsupport event="onclick" action="{!retrieveService}" reRender="ch1"/>
         </apex:inputCheckbox>
        </apex:pageblocksectionitem>

        <apex:pageblockSectionItem >
        <apex:outputLabel >Coach-Builder services</apex:outputLabel>
        <apex:inputCheckbox value="{!strCBservice}"> <apex:actionsupport event="onclick" action="{!retrieveService}" reRender="ch2"/>             
        </apex:inputCheckbox>
        </apex:pageblockSectionItem>

        <apex:pageblockSectionItem >
        <apex:outputLabel >Other services</apex:outputLabel>
        <apex:inputCheckbox value="{!strOtherservice}">  <apex:actionsupport event="onclick" action="{!retrieveService}" reRender="ch3"/>          
        </apex:inputCheckbox>
        </apex:pageblockSectionItem>

        <apex:pageblockSectionItem >
        <apex:outputLabel >Contremarque options</apex:outputLabel>
        <apex:inputCheckbox value="{!strContreOption}">   <apex:actionsupport event="onclick" action="{!retrieveService}" reRender="ch4"/>         
        </apex:inputCheckbox>
        </apex:pageblockSectionItem>

        </apex:pageblocksection>

</apex:pageBlock>

</apex:form>
</apex:page>

Apex:

public class Rfleet_AdditionalServices_CLS {

public String strCurrentRecId{get;set;}
public String strOrderId{get;set;}
public String strOptionVal {get;set;}
public String strCarsetOption{get;set;}
public string strNWservice{get;set;}
public string strCBservice{get;set;}
public string strOtherservice{get;set;}
public string strContreOption{get;set;}
public boolean boolShowSave {get;set;}

public boolean boolService {get;set;}
public List<Service__c> lstService ;

public List<Service__c> lstAllService ;
Map<String, Service__c> mapUniqueService ;
public List<Rfleet_Car_Set__c> lstCarset=new List<Rfleet_Car_Set__c>();

    public Rfleet_AdditionalServices_CLS(ApexPages.StandardController controller) {

        strCurrentRecId= apexPages.currentPage().getParameters().get('carSetID');
        strOrderId=apexPages.currentPage().getParameters().get('orderID');
        List<Rfleet_Car_Set__c> lstValidNetwork=[select id,Rfleet_Create_Network_Mail__c from Rfleet_Car_Set__c where id=:strCurrentRecId];

        for(Rfleet_Car_Set__c validNetwork: lstValidNetwork) {

            system.debug('<<<<< inside for'); 
                boolShowSave = validNetwork.Rfleet_Create_Network_Mail__c;
                system.debug('<<<<< boolShowSave '+boolShowSave );   
            }

        boolService =true;


     }

    public List<SelectOption> getOptions() {

        List<SelectOption> lstOptions  = new List<SelectOption>();
        lstCarset=[select name from Rfleet_Car_Set__c where Order__c=:strOrderId];
        lstOptions .add(new SelectOption('','--None--'));
        for(Rfleet_Car_Set__c strC2Goptions:lstCarset) {
            if(strC2Goptions.id!=strCurrentRecId)
            lstOptions .add(new SelectOption(strC2Goptions.id,strC2Goptions.name));
        }

        return lstOptions ;
    }



     public List<Service__c> retrieveService() {

        system.debug('Selected Values >>>>'+strCarsetOption+strNWservice+strCBservice+strOtherservice+strContreOption);
        lstService =new  List<Service__c>();
        lstAllService =new  List<Service__c>();

           if(strNWservice=='true') {

            List<Service__c> lstSNWService=[SELECT id,Displayed_Code_Label__c,Name,Service_Type__c,Simple_service_type__c,Simple_Product__c,Code__c,Label__c,Rfleet_VAT_Rate__c,Rfleet_TTC_Amount__c,Car_Set__c,Price_HT__c,Customer_Sales_Price_HT__c,Quantity__c,Simple_Product__r.Rfleet_Active_Service__c from Service__c where Service_Type__c='Simple product' and Simple_service_type__c='Network'  and Car_Set__c=:strCarsetOption];
            List<Service__c> lstCNWService=[select id,name,Displayed_Code_Label__c,Car_Set__c from Service__c where Service_Type__c='Simple product' and Simple_service_type__c='Network' and Car_Set__r.Rfleet_Create_Network_Mail__c=true and Car_Set__c=:strCurrentRecId];
            lstService =getUniqueRecords(lstCNWService,lstSNWService,boolShowSave );
            system.debug('SelectedlstService Network >>>>'+lstService );
            system.debug(' Network size >>>>'+lstService.size() );
            lstAllService .addAll(lstService );

        } 

        if(strCBservice=='true') {

            List<Service__c> lstSCBService=[select id,name,Displayed_Code_Label__c,Service_Type__c,Rfleet_CB_Account__c,CB_Options_repository__c,CB_Services_Repository__c,Code__c,Label__c,Rfleet_VAT_Rate__c,Rfleet_TTC_Amount__c,Price_HT__c,Customer_Sales_Price_HT__c,Quantity__c,CB_Services_Repository__r.Rfleet_Active_Service__c from Service__c where Service_Type__c='Coach-Builder' and Car_Set__c=:strCarsetOption];
            List<Service__c> lstCCBService=[select id,name,Displayed_Code_Label__c from Service__c where Service_Type__c='Coach-Builder' and Car_Set__c=:strCurrentRecId];
            lstService =getUniqueRecords(lstCCBService,lstSCBService,boolService );
            system.debug('SelectedlstService coachbuider>>>>'+lstService );
            system.debug(' strCBservice size >>>>'+lstService.size() );
            lstAllService .addAll(lstService );
        }


        if(strContreOption=='true') {

            List<Service__c> lstSContreOption=[SELECT id,Displayed_Code_Label__c,Name,Service_Type__c,Simple_service_type__c,Simple_Product__c,Code__c,Label__c,Rfleet_VAT_Rate__c,Rfleet_TTC_Amount__c,Car_Set__c,Price_HT__c,Customer_Sales_Price_HT__c,Quantity__c,Simple_Product__r.Rfleet_Active_Service__c from Service__c where Service_Type__c='Simple product' and Simple_service_type__c='Contremarque Option' and Car_Set__c=:strCarsetOption];
            List<Service__c> lstCContreOption=[select id,name,Displayed_Code_Label__c,Car_Set__c from Service__c where Service_Type__c='Simple product' and Simple_service_type__c='Contremarque Option' and Car_Set__c=:strCurrentRecId];
            lstService =getUniqueRecords(lstCContreOption,lstSContreOption,boolService );
            system.debug('SelectedlstService contramaque>>>>'+lstService );
            system.debug(' strContreOptionsize >>>>'+lstService.size() );
            lstAllService .addAll(lstService );
        }

        if(strOtherservice=='true') {

            List<Service__c> lstSOthrService=[SELECT id,Displayed_Code_Label__c,Name,Service_Type__c,Simple_service_type__c,Simple_Product__c,Code__c,Label__c,Rfleet_VAT_Rate__c,Rfleet_TTC_Amount__c,Car_Set__c,Price_HT__c,Customer_Sales_Price_HT__c,Quantity__c,Simple_Product__r.Rfleet_Active_Service__c from Service__c where Service_Type__c='Simple product' and Simple_service_type__c='Other' and Car_Set__c=:strCarsetOption];
            List<Service__c> lstCOthrService=[select id,name,Displayed_Code_Label__c,Car_Set__c from Service__c where Service_Type__c='Simple product' and Simple_service_type__c='Other' and Car_Set__c=:strCurrentRecId];
            lstService =getUniqueRecords(lstCOthrService,lstSOthrService,boolService );
            system.debug('SelectedlstService otherService>>>>'+lstService );
            system.debug('strOtherservice size>>>>'+lstService.size() );
            lstAllService .addAll(lstService );
        }

           system.debug('final>>>>'+lstAllService );
           system.debug('lstAllService size>>>>'+lstAllService .size() );
           return lstAllService ;

      } 

    public Pagereference saveService() {

   if(strCarsetOption!=null &&(strNWservice=='true'||strCBservice=='true'||strOtherservice=='true'||strContreOption=='true') ) {
        List<Service__c> lstSaveService=retrieveService();
        system.debug('lstSaveService>>>>'+lstSaveService);
        try {


            if(lstSaveService.size()>0) {
                insert lstSaveService;  system.debug('insert>>>>'+lstSaveService+lstSaveService.size());                   
            }

            return new Pagereference ('/'+strCurrentRecId);
        } catch( Exception ex) {
            return null; 
        }
     }

      else{
              system.debug('The error has occured');
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.error,'Choose atleast one picklist and checkbox value')) ;       return null;
        }

    }

public Pagereference cancel() { return new Pagereference ('/'+strCurrentRecId); }


    public List<Service__c>  getUniqueRecords(List<service__c> lstCurrentRecord,List<service__c> lstSelectedRecord,Boolean boolAddService ) {


        system.debug('lstCurrentRecord<<<<'+lstCurrentRecord);
        system.debug('lstSelectedRecord <<<<'+lstSelectedRecord );
        mapUniqueService = new map<String, Service__c>();
        List<Service__c> lstServiceAdd=new  List<Service__c>();
        if(boolAddService ) {
        if(lstCurrentRecord.size()>0) {   
            for(Service__c objService: lstCurrentRecord) {

                         mapUniqueService.put(objService.Displayed_Code_Label__c,objService); 
            }
        }  
        system.debug('<<<<mapUniqueService'+mapUniqueService);
        if(lstSelectedRecord .size()>0) {
            for(Service__c sObjService: lstSelectedRecord ) {
                system.debug('selObjService<<<'+sObjService);  

                if(!mapUniqueService.containsKey(sObjService.Displayed_Code_Label__c )&& mapUniqueService.size()>0 ) {

                    Service__c serv=new Service__c();
                    serv = sObjService.clone();
                    serv.Car_Set__c=strCurrentRecId;
                    if(serv.Simple_Product__r.Rfleet_Active_Service__c==true&&serv.Simple_Product__c!=null) { system.debug('<first if');lstServiceAdd.add(serv); }
                    else if(serv.Service_Type__c=='Simple product'&& serv.Simple_Product__r.Rfleet_Active_Service__c==true&&serv.Simple_Product__c!=null) {system.debug('<Second if'); lstServiceAdd.add(serv); }
                    else if(serv.Simple_Product__c==null && serv.CB_Services_Repository__r.Rfleet_Active_Service__c==true&&serv.CB_Services_Repository__c!=null ){lstServiceAdd.add(serv); }
                    system.debug('<<<<Else lstServiceAdd<<'+lstServiceAdd);

                } else if(mapUniqueService.size()==0){

                    Service__c serv=new Service__c();
                    serv = sObjService.clone();
                    serv.Car_Set__c=strCurrentRecId;

                    if(serv.Simple_Product__r.Rfleet_Active_Service__c==true&&serv.Simple_Product__c!=null) { system.debug('<first if');lstServiceAdd.add(serv); }
                    else if(serv.Service_Type__c=='Simple product'&& serv.Simple_Product__r.Rfleet_Active_Service__c==true&&serv.Simple_Product__c!=null) {system.debug('<Second if'); lstServiceAdd.add(serv); }
                    else if(serv.Simple_Product__c==null && serv.CB_Services_Repository__r.Rfleet_Active_Service__c==true&&serv.CB_Services_Repository__c!=null ){lstServiceAdd.add(serv); }
                    system.debug('<<<<Else lstServiceAdd<<'+lstServiceAdd);
                }       
            }
        }
       }
        return lstServiceAdd;
    }

}

Best Answer

Your Visualforce invokes 3 controller methods:

... action="{!saveService}" ...
... action="{!cancel}" ...
... action="{!retrieveService}" ...

that are required to have a return type of PageReference or void so it is clear which one is causing the problem:

public Pagereference saveService() {
public Pagereference cancel() {
public List<Service__c> retrieveService() {

So change it to:

public Pagereference retrieveService() {
    ...
    return null;
}

and any modifications it makes to data presented inside the rerender area will be automatically presented.