I have a Visualforce page for creating new Cases. During this process, I want to retrieve the contact's mailing address whenever the contact lookup field is changed.
I'm using ActionSupport but it's not working. When I enter a value in the contact lookup field and check the view state, caseMR is always null and so there's no value for the lookup field either.
I've tried a few things like using/not using immediate="true" or using/not using but nothing changes.
I've looked at this thread but it doesn't work for me. Have I missed something obvious? Populate address field upon Contact lookup selection
Keep in mind that I am creating a new Case in the Visualforce page, not working with an existing case.
I'm wondering if I have to save the Case first before I can do the contact lookup cleanly.
Thanks!
Here's my VF page:
<apex:page standardController="Case" extensions="tempLookup" showHeader="true" id="casePage" >
<apex:pageMessages id="pageMessages" />
<apex:form id="casePageForm">
<apex:pageBlock title="Case" id="casePageBlock" >
<apex:ActionRegion >
<apex:pageBlockSection title="Case Detail" columns="1" collapsible="false" id="caseDetail">
<apex:pageBlockSectionItem id="caseContactItem">
<apex:outputLabel value="Contact" />
<apex:inputField value="{!caseMR.ContactId}" required="true" id="caseContact">
<apex:actionSupport event="onchange" immediate="true" action="{!obtainAddress}" rerender="resContactAddress" />
</apex:inputField>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:ActionRegion>
<apex:pageBlockSection title="Contact Address Info" id="ResContactAddress" >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Contact Mailing Street" />
<apex:outputText value="{!con.MailingStreet}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here's my class:
public class tempLookup {
public Case caseMR { get; set; }
public Contact con { get; set; }
public tempLookup(ApexPages.StandardController std) {
caseMR = (Case)std.getRecord();
}
public void obtainAddress() {
if(caseMR.ContactId != null) {
con = [select MailingStreet from Contact where Id = :caseMR.ContactId];
}
}
}