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
charlie_vcharlie_v 

List of Contacts for current page's Account id

Using a custom controller, I am selecting id, name, etc from Account where id = current page's accountid.  That seems to be working fine.

Next, I need to list all of the Contacts for the account in a drop-down list on my Apex page.  Once a user selects a Contact, I need to capture and store the contactid.

This is the error message I keep getting:  Compile Error: Constructor not defined: [System.SelectOption].<Constructor>(Id) at line 18 column 29

Here's my class code.  What am I doing wrong?  I lifted this from an example shown at http://forums.sforce.com/sforce/board/message?board.id=Visualforce&message.id=2344.

Code:
public class comboOppController {

    public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
    public String selectedContact {get;set;}
    
    public List<SelectOption> contactList;
    
    public List<SelectOption> getContact () {
        if (contactList == null) {
            List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
            
        contactList = new List<SelectOption>();
        for (Contact c : contactee) {
            contactList.add(new SelectOption(c.id));
        }
    }
    return contactList;
    }

}

 

Ron HessRon Hess
this takes two parameters

example

options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));



the first one is the value , the second is the label shown in the picklist
charlie_vcharlie_v
Thanks Ron, but now I get 2 errors:

Error: javax.el.ELException: Cannot coerce from class core.apexpages.el.adapters.metadata.SObjectMetadataELAdapter to interface common.apex.SObjectRow
Error: Cannot coerce from class core.apexpages.el.adapters.metadata.SObjectMetadataELAdapter to interface common.apex.SObjectRow

I changed that line of code to:

Code:
contactList.add(new SelectOption(c.id,c.name));

 

Ron HessRon Hess
that is strange, i was able to save that controller correctly.

are you in the browser or Eclipse?

i did this in the browser.
charlie_vcharlie_v
Browser.  Firefox version 3.0.1
Ron HessRon Hess
strange, you may have something else going on in your org that prevents this save from working.

here is my complete src, see if you can save this in a fresh class
Code:
public class boardtest {


    public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
    }
    
    public String selectedContact {get;set;}
    
    public List<SelectOption> contactList;
    
    public List<SelectOption> getContact () {
        if (contactList == null) {
            List<Contact> contactee = [select id, name, contact.accountid from Contact where contact.accountid = :ApexPages.currentPage().getParameters().get('id')];
            
        contactList = new List<SelectOption>();
        for (Contact c : contactee) {
            contactList.add(new SelectOption( c.id, c.name ));
        }
    }
    return contactList;
    }

}

 


Message Edited by Ron Hess on 08-07-2008 09:44 AM
charlie_vcharlie_v
Wow...created new class with your code above and it works just fine.  That's really frustrating...I was up until 1:30am this morning trying to get this to work.

Anyway, thanks Ron.  I really appreciate your help!
Ron HessRon Hess
cant refund your lost sleep, glad it worked.

check that all the classes in your org are valid, you may have to re-compile some of them as dependent classes are modified.

you also get the award for longest object name in an error message that i've seen in a while...
charlie_vcharlie_v
lol...will do.  Thanks again for your help.
MCPMCP
Hi charlie_v.   I'm trying this but couldn't display the pick list for the contact names. Would you be able to share your code for the page? Thanks!