0

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>

Error:(Nothing is happening) enter image description here

  • What you mean by Nothing is happening? Do you want to display selectedveh list? – Reshma Feb 21 '17 at 5:59
  • @Reshma I am rendering the list . I am unable to see the vlaues from the list i.e(Model__C). – Sathish Feb 21 '17 at 6:04
  • How do you get value in selectedCase? – Reshma Feb 21 '17 at 6:31
  • I didnt get any value in that I just debugged whether it is in th constructor. Do u have any Idea.... – Sathish Feb 21 '17 at 11:23
  • From where did you invoke this page? – Reshma Feb 21 '17 at 11:34
0

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

<apex:page standardController="Case" extensions="RelatedController" >
    <apex:form>
        <apex:actionRegion>
            <apex:inputField value="{!selectedCase.VIN__c}">
                <apex:actionSupport event="onchange" action="{!readUser}" reRender="section"  /> 
            </apex:inputField>
            <apex:outputPanel id ="section">
                <apex:repeat var="a" value="{!selectedveh}">
                    <apex:outputText value="{!a.Name}"/>
                </apex:repeat>
            </apex:outputPanel>
        </apex:actionRegion>
    </apex:form>
</apex:page>

Controller

public class RelatedController {
    public Case selectedCase {get;set;}
    public List<VEH_Veh__c> selectedveh {get;set;}
    public RelatedController(ApexPages.StandardController std){
        if(selectedCase==null){
            selectedCase = new Case();
        }
    }
    public PageReference readUser(){
        selectedveh = [SELECT Name FROM VEH_Veh__c WHERE Id = :selectedCase.VIN__c];
        System.debug('%%'+selectedveh+'%%'+selectedCase.VIN__c);
        return null;
    }
}
0

You need to assign your standard controller's record to your selectedCase first (with proper SOQL).

Update your constructor with the following code:

public RelatedController(ApexPages.StandardController std)
{
    stdCtrl=std;
    selectedCase = [Select Id, Name, VIN__c From Case Where Id =: std.getId()];
}
  • Its not working .... I tried with you snippet. – Sathish Feb 21 '17 at 11:24

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.