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
Matthew BirckbichlerMatthew Birckbichler 

Visual Unkown Property

I know im missing something simple but cannot figure out what,
I am trying to have the user select an sObject from a list and getting an error when trying to save VF -- Unknown property 'CustomPdfController.allObjectsList'

VF Code:
<apex:page controller="CustomPdfController" >
    <apex:form>
        <apex:pageblock>
            <apex:outputLabel value="Choose Object: "></apex:outputLabel>
            <apex:selectList value="{!allObjectsList}"></apex:selectList>
        </apex:pageblock>
    </apex:form>
</apex:page>


APEX Code:
public with sharing class CustomPdfController {
    public list<SelectOption> allObjectsList(){
        list<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
        list<SelectOption> options = new list<SelectOption>();
        options.add(new SelectOption('','--SELECT--'));
        for(Schema.SObjectType gd1:gd){
            options.add(new SelectOption(gd1.getDescribe().getName(),gd1.getDescribe().getName()));
        }
        options.sort();
        return options;
    }
}
Best Answer chosen by Matthew Birckbichler
William TranWilliam Tran
In your VF Code: 

Change this:   <apex:selectList value="{!allObjectsList}"></apex:selectList>

To this:

<apex:SelectList value="{!val}">
<apex:selectOptions value="{!allObjectsList}">
</apex:selectOptions>
</apex:SelectList>


Add this to your apex code
public String val {get;set;}

Basically, the allObjectsList are the OPTIONS, the value selected will be stored in the variable val which you will add in your Apex code.

As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.

Thanks

All Answers

James LoghryJames Loghry
Visualforce looks for getters and setters when accessing properties, like allObjectsList.  Your method is NOT a getter.  Either you can simply add "get" to the beggining of allObjectsList in your method declaration, or you can use the popular get; set; syntax like below:
 
public list<SelectOption> allObjectsList(){
        get{
            list<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
            list<SelectOption> options = new list<SelectOption>();
            options.add(new SelectOption('','--SELECT--'));
            for(Schema.SObjectType gd1:gd){
                options.add(new SelectOption(gd1.getDescribe().getName(),gd1.getDescribe().getName()));
            }
            options.sort();
            return options;
        }
    }

 
James LoghryJames Loghry
Also, when you post code, please use the code format button (< >).  Thanks!
William TranWilliam Tran
In your VF Code: 

Change this:   <apex:selectList value="{!allObjectsList}"></apex:selectList>

To this:

<apex:SelectList value="{!val}">
<apex:selectOptions value="{!allObjectsList}">
</apex:selectOptions>
</apex:SelectList>


Add this to your apex code
public String val {get;set;}

Basically, the allObjectsList are the OPTIONS, the value selected will be stored in the variable val which you will add in your Apex code.

As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.

Thanks
This was selected as the best answer
Matthew BirckbichlerMatthew Birckbichler
William, I tried what you suggested but still get the same eroor
William TranWilliam Tran
Matthew,

Here you go, just cut and paste the code, since you never declare a variable AllObjectsList, you need to turn the method into a getter method by putting a get in front.

thx

VF Code:
<apex:page controller="CustomPdfController" >
    <apex:form >
        <apex:pageblock >
            <apex:outputLabel value="Choose Object: "></apex:outputLabel>
            <apex:SelectList value="{!val}">
            <apex:selectOptions value="{!allObjectsList}">
            </apex:selectOptions>
            </apex:SelectList>
        </apex:pageblock>
    </apex:form>
</apex:page>

APEX CODE:
 
public with sharing class CustomPdfController {

public String val {get;set;}

    public list<SelectOption> getAllObjectsList(){

        list<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
        list<SelectOption> options = new list<SelectOption>();
        options.add(new SelectOption('','--SELECT--'));
        for(Schema.SObjectType gd1:gd){
            options.add(new SelectOption(gd1.getDescribe().getName(),gd1.getDescribe().getName()));
        }
        
        options.sort();
        return options;
        
    }
}