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
Rakesh M 20Rakesh M 20 

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

public class WorkBenchControllerClass {
     public String obj;
    public List<String> objFields {get;set;}
    
    public WorkBenchControllerClass() 
    {    
    }
    public String getobj()
    {
        return obj;
    }
     public void setobj(String obj)
    {
        this.obj = obj;
    } 
    
//Fetching Sobjects
public List<SelectOption> getobjectnames()
{
    Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    System.debug('globaldesc values--> '+schemaMap);
    List<SelectOption> options=new List<SelectOption>();
    options.add(new SelectOption('None','None'));
    for(Schema.SObjectType objType : schemaMap.values())
    {
    options.add(new SelectOption(objType.getDescribe().getName(),objType.getDescribe().getName()));
    }
    return options;
}
 
//Fetching Fields
 public List<SelectOption> fetchFields()
    { 
        List<SelectOption> allfields=new List<SelectOption>();
        List<String> fields = new List<String>();
        Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
        System.debug('Selected Object is ' + obj);
        Schema.sObjectType objType = globalDescription.get(obj); 
        System.debug('Object Type is ' + objType);
        Schema.DescribeSObjectResult r1 = objType.getDescribe(); 
        
        Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap();  

        for(Schema.SObjectField field : mapFieldList.values())  
        {  
            Schema.DescribeFieldResult fieldResult = field.getDescribe();  
            
            if(fieldResult.isAccessible())  
            {  
                System.debug('Field Name is ' + fieldResult.getName());
                //fields.add(fieldResult.getName());
                allfields.add(new SelectOption(fieldResult.getName(),fieldResult.getName()));
            }  
        }
        return allfields;
             
    }   
}
I Tried PageReference also but its not working because.it should return list of fields.
Please Help Me to fix this error
leonardokipperleonardokipper
What's the purpose of the fetchFields() method? Should it populate a combobox/picklist displayed in the Visualforce?
 
Rakesh M 20Rakesh M 20
yes it shoud display picklist (all the fields) in the visualforce
leonardokipperleonardokipper
The error "Apex action method must be a PageReference" is happening because you are trying to use fetchFields as an action (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_controller_setter_methods.htm) .

You could resolve that by changing fetchFields to getfetchingFields()
and creating a public String selectedOption{get;set;} to store the selected option.

Ps. I don't know how you are populating the obj field, used on fetchFields methods.

In Visualforce:
<apex:form >
        <apex:selectList value="{!selectedOption}" size="1">
            <apex:selectOptions value="{!fetchFields}"/>
        </apex:selectList>
</apex:form >

References:
https://www.salesforcetutorial.com/salesforce-picklist-example-visualforce-page/
https://developer.salesforce.com/forums/?id=9060G0000005TBnQAM