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

Referencing Contact in Custom Controller is my problem.  I want to have a user select a contact related to an account from a Select List.  My understanding is that the selected option is returned as a string, which in this case is the contact ID.  How, in the controller do I then reference the contact.  I know how to reference the contact in the Apex Page, but I want to be able to see the contact information on my next Apex Page and save the contact to a new opportunity that I am creating next.



public class testController {
   public Account getAccount() {
        return [select id, Name, Phone from Account
        where id = :ApexPages.currentPage().getParameters().get('id')];
   Contact contact;
    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(,;
    return contactList;

  public PageReference step2() {
     string acctid = ApexPages.currentPage().getParameters().get('id');
     PageReference newPage = new pageReference('/apex/newQuote2?id=' + acctid);
     return newPage.setRedirect(true);





Thanks for any and all assistance.




could you post your VFPage code too?

dmotedmote is the page



<apex:page controller="testController" tabStyle="Opportunity">
  <apex:pageMessages id="msgs"/>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
     return false;

  <apex:sectionHeader title="New Customer Quick Quote" subtitle="Step 1 of 3"/>
    <apex:form >
      <apex:pageBlock title="Customer Information" mode="edit">
              <apex:pageBlockButtons >
          <apex:commandButton action="{!step2}" value="Next"/>
          <apex:commandButton action="{!cancel}" value="Cancel" 
                              onclick="return confirmCancel()" immediate="true"/>

      <apex:pageBlockSection title="Account Information">
        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->  
              You are viewing the {!} account. <p/>
      <apex:pageBlockSection title="Contacts">
         Please Select a Contact.<p/>
         <apex:selectList value="{!selectedContact}" multiselect="false">
            <apex:selectOptions value="{!contact}"/>





Am I not making sense here?  Can someone please help me.  I simply want to select a contact from a contact list and be able to assign an opportunity to the contact.


This is really frustrating.






you will get the contact id in the "selectedcontact" variable. You will need to update the opportunity record  with that selectedcontact assign to opportunity's contact lookup field.