0

I have a master detail relation with Account(master) and Address_vod__c (child). I am showing Account as apex input field. Now on change of Account field , address values also need to changed. Please find below what I have tried.

Apex Page

 <apex:inputField value="{!Form_Requests_abv__c.Account_abv__c}" required="true"  id="check" />

<apex:pageBlockSectionItem >
        <apex:outputText value="Address"  />

      <apex:outputPanel styleClass="requiredInput" layout="block" id="pwPanel" >
      <apex:outputPanel styleClass="requiredBlock"/>  
     <apex:actionRegion >
        <apex:selectList size="1" value="{!AddressID}" required="true" >
          <apex:selectOptions value="{!address}" ></apex:selectOptions>
          <apex:actionSupport event="onchange" rerender="check" action="{!address}" status="Status1"/>
      </apex:selectList>


       <apex:actionStatus id="Status1" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:actionRegion>
            </apex:outputPanel> 
   </apex:pageBlockSectionItem>

Apex code

public List<SelectOption> getAddress()
 {  AddID= new Set<ID>();
 act =System.currentPageReference().getParameters().get('ABC');
     List<SelectOption> optionaddress = new List<SelectOption>();
     optionaddress.add(new selectoption('none','---Select--'));
     for(Account ac: [Select Id,Name From Account where ID=:Test.Account_abv__c])
     {

       for(Address_vod__c c: [Select Id,Name,Address_line_2_vod__c, City_vod__c , State_vod__c , Zip_vod__c From Address_vod__c where Account_vod__c=:ac.ID ])      
        {  if(c!=null){
             AddID.add(c.ID);
             }

        Address=c.Name+','+c.Address_line_2_vod__c+','+c.City_vod__c+','+c.State_vod__c+','+c.Zip_vod__c;


         optionaddress.add(new SelectOption(c.ID,Address));
        }


     }


     return optionaddress;    


}
4
  • What's your problem? I think you need to add an action support with the event "onchange' on the account input field wich calls a method which reload the adresses. – Martin Lezer Feb 19 '16 at 13:34
  • I have getAccount method where I am preparing the data. Issue is with my above code Address field is always null. – Testing_SFDC Feb 19 '16 at 13:44
  • Where does this variable "Test.Account_abv__c" come from? – Martin Lezer Feb 19 '16 at 13:46
  • Test is the instance of object in standard controller. Account_abv__c is a field of it. Actually I need to pass the selected Account's ID there but not getting the way to do. – Testing_SFDC Feb 19 '16 at 13:49
1

I hope I understand well what you want to do.

public List<SelectOption> getAddress()
 {  AddID= new Set<ID>();
 act =System.currentPageReference().getParameters().get('ABC');
     List<SelectOption> optionaddress = new List<SelectOption>();
     optionaddress.add(new selectoption('none','---Select--'));
     for(Account ac: [Select Id From Account where ID=:Form_Requests_abv__c.Account_abv__c])
     {

       for(Address_vod__c c: [Select Id,Name,Address_line_2_vod__c, City_vod__c , State_vod__c , Zip_vod__c From Address_vod__c where Account_vod__c=:ac])      
        {  if(c!=null){
             AddID.add(c.ID);
             }

        Address=c.Name+','+c.Address_line_2_vod__c+','+c.City_vod__c+','+c.State_vod__c+','+c.Zip_vod__c;


         optionaddress.add(new SelectOption(c.ID,Address));
        }


     }


     return optionaddress;    


}
6
  • Thanks, but it is throwing below error. Compile Error: Invalid bind expression type of Schema.SObjectField for column of type Id. – Testing_SFDC Feb 19 '16 at 14:03
  • I just edited my code to avoid this error. – Martin Lezer Feb 19 '16 at 14:10
  • Hi, it's still there , same error. – Testing_SFDC Feb 19 '16 at 14:19
  • What's the code of the row causing the error? – Martin Lezer Feb 19 '16 at 14:21
  • This is the line. for(Address_vod__c c: [Select Id,Name,Address_line_2_vod__c, City_vod__c , State_vod__c , Zip_vod__c From Address_vod__c where Account_vod__c=:Form_Requests_abv__c.Account_abv__c.ID ]) – Testing_SFDC Feb 19 '16 at 14:29

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.