I have a getter method to create a SelectOption. I want to put all the keys in Returned value to a List in another Method.

public List<SelectOption> getsortlist() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('Parent.Profile.Name','Profile Name')); 
        options.add(new SelectOption('sObjectType','sObject'));  
        return options; 

and retrieving the values here

List<SelectOption>  opt = getsortlist();
List<String>  theList = opt.getValue();

Error is

Method does not exist or incorrect signature: void getValue() from the type List

How to solve this issue?

  • Why can't you maintain a global list/Map? You may iterate through the List/Map to add SelectOption values and use the same in a different method maybe. You can use List type Custom setting if you're OK with approach – L Mudiyanse Jul 13 '17 at 10:20

You can't do this in a list you need a loop to get all value then you can add them in a list. getValue() works for single variable not for a list.

List<String>  theList = new List<String>();
for(SelectOption so : getsortlist())

SelectOption GetValue


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.