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
sonali  vermasonali verma 

action support not working

Hi
I wan to display all contacts associated with account name once the account is seledted through a lookup in a selarate pagebblock table
in same vf page.
public class SelectAccountThroughLookup
{
    //I need to select account name from contact lookup. so I need variable of type contact
    private Contact con;
    
    public boolean check{get;set;}
    
    public SelectAccountThroughLookup(ApexPages.StandardController stdcontroller) 
    {
      this.con=(Contact)stdcontroller.getRecord();
    }
    
    public SelectAccountThroughLookup()
    {
      //check=false;
    }
    
    public List<Contact> getShowContactName()
    {
      List<Contact> conList=[select LastName from Contact where Name=:con.AccountID];
      return conList;
    }
 
}
<apex:page standardController="contact"
           extensions="SelectAccountThroughLookup">

<apex:form >
<apex:pageBlock title="Select Account Name from Lookup">
<apex:outputLabel >Select Account Name</apex:outputLabel>

<apex:inputField id="field1"
                 value="{!Contact.AccountID}">
         
 <apex:actionSupport event="onchange"
                     id="id1"
                     reRender="check"/>
                                         
 </apex:inputField>
</apex:pageBlock>

<apex:outputPanel id="check">
<apex:pageBlock title="Contact Details">
<apex:pageBlockTable value="{!showContactName}"
                     var="c">
        <apex:outputText value="{!c.LastName}"></apex:outputText>
         
</apex:pageBlockTable>
   
</apex:pageBlock>
</apex:outputPanel>
</apex:form>           
</apex:page>
But action support is not working . pls guide me.

Thanks
sonali
 
Best Answer chosen by sonali verma
Dayakar.DDayakar.D
Hi sonali verma,

every thing is fine in your code, here the problem is in your contact query, you are trying to query list of contacts having name as its account id, change the query as 
List<Contact> conList=[select LastName,email from Contact where AccountId=:con.AccountID];

and use 
<apex:column value="{!c.LastName}"/>

Instead of  using 
<apex:outputtext value="{!c.LastName}"/>

Please change your code as below, it will work.
<apex:page standardController="contact"
           extensions="SelectAccountThroughLookup">
    
    <apex:form >
        <apex:pageBlock title="Select Account Name from Lookup">
            <apex:outputLabel >Select Account Name</apex:outputLabel>
            
            <apex:inputField id="field1"
                             value="{!Contact.AccountID}">
                
                <apex:actionSupport event="onchange"
                                    id="id1" 
                                    reRender="check"/>
                
            </apex:inputField>
        </apex:pageBlock>
        
        <apex:outputPanel id="check">
            <apex:pageBlock title="Contact Details">
                <apex:pageBlockTable value="{!showContactName}"
                                     var="c">
                    <apex:column value="{!c.LastName}"/>
                    <apex:outputtext value="{!c.LastName}"/>
                    <apex:column value="{!c.email}"/>
                </apex:pageBlockTable>
                
            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>           
</apex:page>


public class SelectAccountThroughLookup
{
    //I need to select account name from contact lookup. so I need variable of type contact
    private Contact con;
    
    public boolean check{get;set;}
    
    public SelectAccountThroughLookup(ApexPages.StandardController stdcontroller) 
    {
      this.con=(Contact)stdcontroller.getRecord();
    }
    
    public SelectAccountThroughLookup()
    {
      //check=false;
    }
    
    public List<Contact> getShowContactName()
    {
        system.debug('con'+con);
      List<Contact> conList=[select LastName,email from Contact where AccountId=:con.AccountID];
        system.debug('listOf contacts'+conList);
      return conList;
    }
 
}

Please let me know, if it works for you.

Best Regards,
Dayakar.D

 

All Answers

Dayakar.DDayakar.D
Hi sonali verma,

every thing is fine in your code, here the problem is in your contact query, you are trying to query list of contacts having name as its account id, change the query as 
List<Contact> conList=[select LastName,email from Contact where AccountId=:con.AccountID];

and use 
<apex:column value="{!c.LastName}"/>

Instead of  using 
<apex:outputtext value="{!c.LastName}"/>

Please change your code as below, it will work.
<apex:page standardController="contact"
           extensions="SelectAccountThroughLookup">
    
    <apex:form >
        <apex:pageBlock title="Select Account Name from Lookup">
            <apex:outputLabel >Select Account Name</apex:outputLabel>
            
            <apex:inputField id="field1"
                             value="{!Contact.AccountID}">
                
                <apex:actionSupport event="onchange"
                                    id="id1" 
                                    reRender="check"/>
                
            </apex:inputField>
        </apex:pageBlock>
        
        <apex:outputPanel id="check">
            <apex:pageBlock title="Contact Details">
                <apex:pageBlockTable value="{!showContactName}"
                                     var="c">
                    <apex:column value="{!c.LastName}"/>
                    <apex:outputtext value="{!c.LastName}"/>
                    <apex:column value="{!c.email}"/>
                </apex:pageBlockTable>
                
            </apex:pageBlock>
        </apex:outputPanel>
    </apex:form>           
</apex:page>


public class SelectAccountThroughLookup
{
    //I need to select account name from contact lookup. so I need variable of type contact
    private Contact con;
    
    public boolean check{get;set;}
    
    public SelectAccountThroughLookup(ApexPages.StandardController stdcontroller) 
    {
      this.con=(Contact)stdcontroller.getRecord();
    }
    
    public SelectAccountThroughLookup()
    {
      //check=false;
    }
    
    public List<Contact> getShowContactName()
    {
        system.debug('con'+con);
      List<Contact> conList=[select LastName,email from Contact where AccountId=:con.AccountID];
        system.debug('listOf contacts'+conList);
      return conList;
    }
 
}

Please let me know, if it works for you.

Best Regards,
Dayakar.D

 
This was selected as the best answer
sonali  vermasonali verma
Hi Dayakar
Thanks, I got the concept. Its working.

Regards
sonali