I'm trying to get the shipping street value that's being shown to dynamically change if the lookup Account field is changed.

enter image description here

Here is the visualforce code that I have so far:

<apex:page lightningStyleSheets="true"
<apex:form >
<apex:pageBlock title="Validate Service Call Details">
    <apex:pageBlockSection columns="2" title="Service Call Details">
        <apex:inputField value="{!c.Equipment_Type__c}"/>
        <apex:inputField value="{!c.Issue_Type__c}"/>
        <apex:inputField value="{!c.Issue_Description__c}"/>
        <apex:inputField value="{!c.Received_Via__c}"/>
        <apex:inputField value="{!c.Customer_PO__c}"/>
    <apex:pageBlockSection columns="2" title="Account Details">
        <apex:inputField value="{!c.AccountId}" id="a"/>
        <apex:outputField value="{!acc.ShippingStreet}"/>            
    <div align="center">
        <apex:commandButton action="{!submit}" value="Submit"/>

Here is the controller I have so far:

public class Case_Convert_to_SC_Controller {

public Case c {get;set;}

public Service_Call__c sc {get;set;}
public Account acc {get;set;}

public Case_Convert_to_SC_Controller(ApexPages.StandardController controller)
    c = new Case();
    c = [SELECT ID, Customer_PO__c, Equipment_Type__c, Issue_Type__c, Issue_Description__c, Received_Via__c, ContactId, AccountId 
              FROM Case WHERE ID = :ApexPages.currentPage().getParameters().get('id')];
    acc = [SELECT ID, ShippingAddress, ShippingStreet
          FROM Account WHERE ID = :c.AccountId];

public PageReference submit()
        return new PageReference('/'+sc.Id);

1 Answer 1


You simply need to add an action support:

    <apex:inputField value="{!c.AccountId}">
      <apex:actionSupport onchange="{!updateAccount}" />


public void updateAccount() {
  if(c.AccountId != null) {
    acc = [SELECT ShippingAddress, ShippingStreet FROM Account WHERE Id = :c.AccountId];
  } else {
    acc = new Account(); // show blank value
  • Adding the action support did it! Thank you. By any chance do you know why it would cause the lookup window to not close on it's own after adding the action support? Not a big issue, I can always tell my users to close the window themselves after they've selected a new account.
    – ad_rey
    Apr 1, 2021 at 15:58
  • @ad_rey Not sure. Check the developer console to see if you get any errors.
    – sfdcfox
    Apr 1, 2021 at 19:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .