+ Start a Discussion
Mohammadasif SiddiquiMohammadasif Siddiqui 

Variable does not exist: conlist

I am getting 2 error in below code.

Variable does not exist: conlist

Unknown property 'AccountController1_picklistrendering.conlist'

 

<apex:page controller="AccountController1_picklistrendering">
   <apex:form >
      <apex:pageBlock title="Account Name">
            Account Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

             <apex:selectList value="{!selectedAccId}" size="1">                                 
                <apex:selectOptions value="{!AccountNames}"/>
                <apex:actionSupport event="onchange" reRender="a"/>
             </apex:selectList>

             <br/><br/>

           Related Contact Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            <apex:pageblock >
   <apex:pageblockTable value="{!conlist}" var="c" id="a">
       <apex:column value="{!c.firstname}"/>
       <apex:column value="{!c.lastname}"/>
       <apex:column value="{!c.email}"/>
       <apex:column value="{!c.accountid}"/>
   </apex:pageblockTable>
</apex:pageblock>

       </apex:pageBlock>               
    </apex:form>
</apex:page>
 
public with sharing class AccountController1_picklistrendering {
    public String selectedAccId{get;set;}
    public String selectedConId{get;set;}
      
          public List<SelectOption> getAccountNames() {
                  List<SelectOption> accOptions= new List<SelectOption>();
                  accOptions.add( new SelectOption('','--Select--'));
                  for( Account acc : [select Id,name from Account ] ) {
                          accOptions.add( new SelectOption(acc.Id,acc.name));
                  }
                 return accOptions;
           }
         
      public pagereference getContactNames()
{
    conlist = [select id,firstname,lastname,email,accountid from contact where accountid=:selectedAccId];
    return null;
}
    }

Please Help me.
Thanks in Advance​​​​​​​
Best Answer chosen by Mohammadasif Siddiqui
ANUTEJANUTEJ (Salesforce Developers) 
Hi Mohammad,

Can you try the below code and check:

>> public with sharing class AccountController1_picklistrendering {
    public String selectedAccId{get;set;}
    public String selectedConId{get;set;}
    public list<contact> conlist{get;set;}
      
          public List<SelectOption> getAccountNames() {
                  List<SelectOption> accOptions= new List<SelectOption>();
                  accOptions.add( new SelectOption('','--Select--'));
                  for( Account acc : [select Id,name from Account ] ) {
                          accOptions.add( new SelectOption(acc.Id,acc.name));
                  }
                 return accOptions;
           }
         
      public void getContactNames()
{
    conlist = [select id,firstname,lastname,email,accountid from contact where accountid=:selectedAccId];
    system.debug(conlist);
    
}
    }

>> <apex:page controller="AccountController1_picklistrendering">
   <apex:form >
      <apex:pageBlock title="Account Name">
            Account Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

             <apex:selectList value="{!selectedAccId}" size="1">                                 
                <apex:selectOptions value="{!AccountNames}"/>
                <apex:actionSupport event="onchange" reRender="a"/>
             </apex:selectList>

             <br/><br/>

           Related Contact Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            <apex:pageblock >
   <apex:pageblockTable value="{!conlist}" var="c" id="a">
       <apex:column value="{!c.firstname}"/>
       <apex:column value="{!c.lastname}"/>
       <apex:column value="{!c.email}"/>
       <apex:column value="{!c.accountid}"/>
   </apex:pageblockTable>
</apex:pageblock>

       </apex:pageBlock>               
    </apex:form>
</apex:page>

In case if it helps can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Mohammad,

Can you try the below code and check:

>> public with sharing class AccountController1_picklistrendering {
    public String selectedAccId{get;set;}
    public String selectedConId{get;set;}
    public list<contact> conlist{get;set;}
      
          public List<SelectOption> getAccountNames() {
                  List<SelectOption> accOptions= new List<SelectOption>();
                  accOptions.add( new SelectOption('','--Select--'));
                  for( Account acc : [select Id,name from Account ] ) {
                          accOptions.add( new SelectOption(acc.Id,acc.name));
                  }
                 return accOptions;
           }
         
      public void getContactNames()
{
    conlist = [select id,firstname,lastname,email,accountid from contact where accountid=:selectedAccId];
    system.debug(conlist);
    
}
    }

>> <apex:page controller="AccountController1_picklistrendering">
   <apex:form >
      <apex:pageBlock title="Account Name">
            Account Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

             <apex:selectList value="{!selectedAccId}" size="1">                                 
                <apex:selectOptions value="{!AccountNames}"/>
                <apex:actionSupport event="onchange" reRender="a"/>
             </apex:selectList>

             <br/><br/>

           Related Contact Names&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            <apex:pageblock >
   <apex:pageblockTable value="{!conlist}" var="c" id="a">
       <apex:column value="{!c.firstname}"/>
       <apex:column value="{!c.lastname}"/>
       <apex:column value="{!c.email}"/>
       <apex:column value="{!c.accountid}"/>
   </apex:pageblockTable>
</apex:pageblock>

       </apex:pageBlock>               
    </apex:form>
</apex:page>

In case if it helps can you please choose this as the best answer so that it can be used by others in the future.

Regards,
Anutej
This was selected as the best answer
Mohammadasif SiddiquiMohammadasif Siddiqui

Thanks, the above error gone but my functionality is not working.

I want to Display list of Account in picklist and when account gets selected its related contacts should be displayed in table