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
Sammy7Sammy7 

pass lookup inputfield to extension

Hi, 
 So I have an input field :<b>To: </b> <apex:inputfield value="{!q.contactid}"/><p/>

and in my controller, I have:
public Quote q {get;set;}

and then I would like to present the email address in this outputfield: <b>NAME: </b> <apex:outputtext value="{!q.contact.name}"/><p/> 

However this is not working, Please help: 
Below is my VF page: 
<apex:page standardController="Quote" extensions="email_class">
    <apex:form >
        <apex:pageBlock title="Email Details" id="ed">
            <b>To: </b> <apex:inputfield value="{!q.contactid}"/><p/>
         <apex:actionSupport event="onchange"  action="{!Contactpopulated}" rerender="ed"/>      
               <b>NAME: </b> <apex:outputtext value="{!q.contact.email}"/><p/> 
.......
.......

and my extension:
public class email_class{
        
    Public string ToAddresses {get;set;}
    Public string CCAddresses {get;set;}
    Public string quoteId {get;set;}
    Public string subject {get;set;}
    public string email_body {get;set;}
    public string emailTo {get;set;}
    public string emailCC {get;set;}
   public Quote q {get;set;}
   // public Contact ct {get;set;}
     public  string [] ccaddress; 
       
        public email_class(ApexPages.StandardController controller) {
                quoteId = ApexPages.currentPage().getParameters().get('id');
              Quote  q= (Quote)controller.getRecord();
    }

             public void Contactpopulated(){
       q.contact=[ Select  email, name From contact where  id=:q.contactid limit 1]; 
}


 
Best Answer chosen by Sammy7
Sami ShakithSami Shakith
Hi Sammy,

Wrap the action support in inputfield tag as like below,
 
​<apex:inputfield value="{!quote.contactid}"><p/> 
<apex:actionSupport event="onchange" action="{!Contactpopulated}" rerender="ed"/> 
​</apex:inputfield>

 

All Answers

Sammy7Sammy7

I modified my code after googling, but still nothing....the email address wont populate. Also my debug log shows nothing as well...plz help.

VF page:
 

<apex:page standardController="Quote" extensions="email_class">
    <apex:form >
           
        <apex:pageBlock title="Email Details" id="ed">
            <b>To: </b> <apex:inputfield value="{!quote.contactid}"/><p/>
          
         <apex:actionSupport event="onchange" action="{!Contactpopulated}"   rerender="ed"/>  
                       
         <b>Email address: </b> <apex:outputfield value="{!con.email}"/><p/
...............


Extension:
public class email_class{
        
    Public string ToAddresses {get;set;}
    Public string CCAddresses {get;set;}
    Public string quoteId {get;set;}
    Public string subject {get;set;}
    public string email_body {get;set;}
    public string emailTo {get;set;}
    public string emailCC {get;set;}
     public  string [] ccaddress; 
     public contact con {get;set;}
      
      private apexpages.standardcontroller stdctrl; 
        public email_class(ApexPages.StandardController controller) {
                stdctrl=controller;
                 quoteId = ApexPages.currentPage().getParameters().get('id');     
    }
           public void Contactpopulated(){
           quote qte= (Quote)stdctrl.getRecord();
          // qte.contact=[select contact.email from Contact where id=:qte.contactid];
           con=[Select email, name from contact where id=:qte.contactid limit 1];
           system.debug('**************'+ qte.contactid);
          // emailTo= qte.contact.email;
       
}
.......
Sami ShakithSami Shakith
Hi Sammy,

Wrap the action support in inputfield tag as like below,
 
​<apex:inputfield value="{!quote.contactid}"><p/> 
<apex:actionSupport event="onchange" action="{!Contactpopulated}" rerender="ed"/> 
​</apex:inputfield>

 
This was selected as the best answer
Sammy7Sammy7
Yes, I figured it out as well.....I keep making these silly errors. Thanks.