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
Dchris222Dchris222 

Compile Error on Extension

I am trying to figure out why this is not compling corrrectly. The error I recieve is: "Error: Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Id) at line 14 column 25." Would appreciate it if you guys could help a new developer out.

 

Chris

 


public class ModalityExtension {
    private Trade_in__c t; //User sobject
    
   
    public ModalityExtension(ApexPages.StandardController stdController) {
        this.t = (Trade_in__c)stdController.getRecord();
    }
    

    public List<selectOption> getModality() {
        List<selectOption> options = new List<selectOption>(); //new list for holding all of the picklist options
        options.add(new selectOption('', '- None -')); //add the first option of '- None -' in case the user doesn't want to select a value or in case no values are returned from query below
        for (Trade_in__c TradeIns : [SELECT Modality2__c FROM Trade_in__c]) {
            options.add(new selectOption(TradeIns.Modality2__c)); //for all records found - add them to the picklist options
        }
        return options; //return the picklist options
    }
}

aalbertaalbert

I believe this line of code is failining

 

options.add(new selectOption(TradeIns.Modality2__c)); 

 

 

You need to pass at least two strings to create a new selectoption. 

Check out the selectoption apex class here