I have about 2 weeks experience in Visualforce and Apex and I am having trouble with displaying an address field related to a contact object. I have a custom Order object called WIMS_Order_c. With a lookup field called Customer_c which is a lookup for the Contact object. All I want to do is upon Customer (contact) lookup selection is to populate the mailing street address label field. However I get the following error after selection:
System.QueryException: List has no rows for assignment to SObject Error is in expression '{!ContactPopulated}' in page orderentrytest2
Class.SFOEController.ContactPopulated: line 13, column 1
Please help. Very much appreciate it. Extension controller and VF code below.
Visual Force
<apex:page standardController="WIMS_Order__c" extensions="SFOEController" sidebar="false" showHeader="false">
<apex:sectionHeader title="Order Entry" subtitle="{!WIMS_Order__c.Customer__c}"/>
<apex:form >
<apex:pageBlock title="Order Entry">
<apex:actionRegion >
<apex:pageBlockSection title="Order Header" columns="2">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Customer"/>
<apex:outputPanel >
<apex:inputField value="{!WIMS_Order__c.Customer__c}">
<apex:actionSupport event="onchange"
action="{!ContactPopulated}"
rerender="thePageBlock"
status="status"/>
</apex:inputField>
<apex:actionStatus startText="applying address..."
id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockSection title="Address" columns="2" id="thePageBlock" rendered="true">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Mailing Address"/>
<apex:outPutField value="{!WIMS_Order__c.Customer__r.MailingStreet}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
EXT Controller
public with sharing class SFOEController
{
private ApexPages.StandardController stdCtrl;
public SFOEController(ApexPages.StandardController std)
{
stdCtrl=std;
}
public void ContactPopulated()
{
WIMS_Order__c cont=(WIMS_Order__c) stdCtrl.getRecord();
cont.Customer__r =[select MailingStreet, MailingCity from contact where id=:cont.id];
}
}