-2

I want to select account in drop down list for ex acc ruchiacc then its related contact name should be display in table .so for that i have tried below code: apex code:

public with sharing class AccountController1_picklistrendering {

    public String account { get; set; }
    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 List<SelectContact> getContactNames()
           {
                  System.debug('Entered ContactNames account id...........'+selectedAccId );

                    if(selectContact != null)

                        contact con = [select name from contact where accountid=:selectedAccId ];

                        return con;


           }
    }

vf page:

<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:pageBlockTable value="{!ContactNames}" var="items">
             <apex:column value="{!items.name}"/>
             </apex:pageBlockTable>
              <apex:selectList value="{!selectedConId}" size="1"  id="a">
                <apex:selectOptions value="{!ContactNames}" />
              </apex:selectList>

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

Based on e.g. Action support Rerender not working adding an apex:outputPanel around your apex:selectList and using its ID in the apex:actionSupport should work.

But before you go to far here, can you guarantee that in your org there will only ever be a limited number of Accounts and that each Account will always have a limited number of Contacts? If your code ran in an org with 100,000 Accounts and some Accounts had 100,000 Contacts you would hit limits in the platform and even if you didn't hit those limits users would be dealing with extremely long lists...

0

try with this

contact con = [select name from contact where contact.accountid=:selectedAccId ];

1
  • Please explain why this would resolve the issue, if it does.
    – Adrian Larson
    Mar 14 '17 at 14:37
0

Change getContactNames method in this way

public pagereference getContactNames()
{
    conlist = [select id,firstname,lastname,email,accountid from contact where accountid=:selectedAccId];
    return null;
}

call the getContactNames method on action Support for call action="{!getContactNames}"

and in visualforce remove related contact form and add in this way

<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>

Later we will check it once

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.