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
vagishvagish 

selectlist help

hi,

    public List<SelectOption> getItems() {
        List<SelectOption> op=new List<SelectOption>();
        for(List<Student__c>student:[select name from Student__c])
        {
        op.add(new SelectOption(student.name));
        }
        return null;
    }

 

In this code, I want to add student names into selectOption, but it is giving error:

Error: nameController Compile Error: Initial term of field expression must be a concrete SObject: LIST<Student__c> at line 7 column 33.

 

Thanks in advance!!

Prafull G.Prafull G.

Please try this one

 

public List<SelectOption> getItems() {
    List<SelectOption> op=new List<SelectOption>();
    for(List<Student__c> student : [select name from Student__c])
    {
        op.add(new SelectOption(student.name, student.name));
    }

    if(op.size() > 0)

        return op;

    return null;
}

 

If still you are facing issues... please post complete controller's code.

 

 

vagishvagish

hi problem get resolved by changing the for loop line like this:

 

for(Student__c student:[select id,name from Student__c])