Apex Class:
public class RelatedController
{
public Case selectedCase { get; set; }
public List<VEH_Veh__c> selectedveh { get; set; }
public RelatedController ()
{
System.debug('selectedCase ----------------------->>'+selectedCase );
}
public List<VEH_Veh__c> readUser()
{
selectedveh = [ Select Id,Model__C from VEH_Veh__c Where Id = :selectedCase.VIN__c ];
System.debug('selectedveh----------------------->>'+selectedveh );
return selectedveh ;
}
private ApexPages.StandardController stdCtrl;
public RelatedController(ApexPages.StandardController std)
{
stdCtrl=std;
}
}
Apex Page:
<apex:page standardcontroller="Case" extensions="RelatedController">
<apex:form >
<apex:pageMessages id="msgs"/>
<apex:pageBlock title="Contact Create/Edit">
<apex:actionRegion >
<apex:pageBlockSection id="accinfo" title="Account Information">
<apex:inputField value="{!selectedCase .VIN__c}">
<apex:actionSupport event="onchange" action="{!readUser}" rerender="section" />
</apex:inputField>
<apex:outputPanel id="section">
<apex:repeat value="{!selectedveh}" var="a">
<apex:outputField value="{!a.Model__c}"/>
</apex:repeat>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockButtons >
<apex:commandButton value="Cancel" action="{!cancel}"/>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Best Answer
You have to use PageReference as a method return type when Apex action method is used. Also inside Constructor you have to either assign the Case (from URL parameter) or Create a new Case based on the scenario (edit or new Case creation).
Your code should somehow look like this. Please modify your code as below. Remember, this is not a compiled code.
VF Page
Controller