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
vijendharvijendhar 

Constructor not defined: [selectoption].<Constructor>(String, String): error in line 17

public class ChildRelationshipExample {
    
    public List<SelectOption> options;
    
    public List<SelectOption> getOptions(){
        return options;
    }
    
    public ChildRelationshipExample(){
        
        options = new List<SelectOption>();
        Schema.DescribeSobjectResult r = Account.SobjectType.getDescribe();
        List<Schema.childRelationship> c = r.getChildRelationShips();
        
        for(schema.childRelationship x:c){
            String name = ' '+x.getChildSObject();
            SelectOption op = new SelectOption(name,name);
            options.add(op);
        }
        
    }
    
    
}


Constructor not defined: [selectoption].<Constructor>(String, String)


can any one help me to solve these problem
Best Answer chosen by vijendhar
Amit Chaudhary 8Amit Chaudhary 8
I agree with James Loghry. Please check you have any class with "SelectOption" then please delete the class and try again

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below code.
public class ChildRelationshipExample {
    
    public List<SelectOption> options;
    
    public List<SelectOption> getOptions(){
        return options;
    }
    
    public ChildRelationshipExample(){
        
        options = new List<SelectOption>();
        Schema.DescribeSobjectResult r = Account.SobjectType.getDescribe();
        List<Schema.childRelationship> c = r.getChildRelationShips();
        
        for(schema.childRelationship x:c)
		{
			if(x.getChildSObject() != null)
			{
				String name = ' '+x.getChildSObject();
				SelectOption op = new SelectOption(name,name);
				options.add(op);
			}	
        }
        
    }
    
    
}

Please let us know if this will help you

Thanks,
Amit Chaudhary
James LoghryJames Loghry
Your constructor looks okay to me.  If the previous options don't work, check to make sure you don't have an Apex class (Setup->Develop->Apex Classes) named "SelectOption" that could be interfering with your save.  
Amit Chaudhary 8Amit Chaudhary 8
I agree with James Loghry. Please check you have any class with "SelectOption" then please delete the class and try again
This was selected as the best answer
Arunkumar RArunkumar R
Hi,

Amit absolutely you are right...!

Vijendhar, You have a class named as "Selectoption" in your organization. Please delete or rename the class, then try again to save your code.

Thanks.