function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Semira@gmail.comSemira@gmail.com 

actionsupport for lookup field not firing

Hi I'm trying to get a value of contact field when the contact is selected through a lookup. But for some reason it's rendering. I'm sure what am I missing or maybe actionsupport isn't the solution?

By the way the Unit is a custome object on where I'm using standard object and calling an extension Class
<apex:actionRegion immediate="true">
    <apex:pageblockSection columns="1" title="Items">
            <apex:outputPanel id="name">
             <apex:pageBlockTable value="{!Item}" var="a" columns="3">      
                <apex:column headerValue="Materials" >
                    <apex:inputfield value="{!a.Contact__c}"/>
                    <apex:actionSupport event="onchange" action="{!getUnit}" rerender="name"/>
                </apex:column>     
                <apex:column headerValue="Unit">
                    <apex:outputfield value="{!Unit.Contact__r.Lastname}"/>
                </apex:column> 
                <apex:column headerValue="ship">
                    <apex:inputfield value="{!a.Job_Role__c}"/>
                </apex:column> 
            </apex:pageBlockTable>
            </apex:outputPanel>

          <apex:pageBlockTable value="{!Item}" var="a" columns="3"> 
           </apex:pageBlockTable>

  </apex:actionRegion>
</apex:pageblockSection>
public with sharing class CreateMaterialItem {

    ApexPages.StandardController JC;
    Public Job_Contact__c Unit {get; set;}
    
    public CreateMaterialItem(ApexPages.StandardController controller) {
        
        Unit = [select id, contact__c, contact__r.lastname from Job_contact__c where job__c =: JC.getID() limit 1];

    }
    public pageReference getUnit(){
         
        for (Job_contact__c lst : [select id, contact__c, contact__r.lastname from Job_contact__c where job__c =: JC.getID() limit 10]) {
                
                Unit.contact__r.lastname = lst.contact__r.lastname;
             }
             return null;
     } 
.
.
.
.
}//end of class
Please please help! This is kind of urgent!


Best Answer chosen by Semira@gmail.com
SarfarajSarfaraj
Hi

These are my findings,
1. Instance variable JC is never initialized. Rewrite your constructor,
public CreateMaterialItem(ApexPages.StandardController controller) {
        JC = controller;
        Unit = [select id, contact__c, contact__r.lastname from Job_contact__c where job__c =: JC.getID() limit 1];

    }

2. You are using actionregion with immediate = true. Double check if you really want this. 

3. Your business requirement is not very clear to me. Specially the getUnit method. It is very difficult to suggest anything else without understanding the requirement. 

--Akram

All Answers

Kiran  KurellaKiran Kurella
You need to associate the actionsupport to your inputField. Try this:

<apex:inputfield value="{!a.Contact__c}" >
     <apex:actionSupport event="onchange" action="{!getUnit}" rerender="name"/>
</apex:inputField>
Semira@gmail.comSemira@gmail.com
@kiran Kurella It is still not working. It's not showing any details. I wonder if my getUnit class fetching any value. Maybe need to re-write that?? 
SarfarajSarfaraj
Hi

These are my findings,
1. Instance variable JC is never initialized. Rewrite your constructor,
public CreateMaterialItem(ApexPages.StandardController controller) {
        JC = controller;
        Unit = [select id, contact__c, contact__r.lastname from Job_contact__c where job__c =: JC.getID() limit 1];

    }

2. You are using actionregion with immediate = true. Double check if you really want this. 

3. Your business requirement is not very clear to me. Specially the getUnit method. It is very difficult to suggest anything else without understanding the requirement. 

--Akram
This was selected as the best answer