+ Start a Discussion
Shravya Rama 9Shravya Rama 9 

Calling a method from lookup field not working

I am making the current user's username and phone number as the default values for the lookup field Fahrer and text field Contact number through constructor. But when I change the lookup field to any other value, I want my contact number to also get updated. But my method is not getting called from the Fahrer look up field. Can anybody suggest a work around.

VF PAGE
<apex:inputField label="Fahrer" value="{!res.Fahrer__c}"   >
                    
<apex:actionSupport action="{!LoadingUserDetails}" rerender="out" />             
               
</apex:inputField>

 <apex:inputField label="Contact Nummer" value="{!currentuser.phone}" rendered="true" id="out" />
Class
 
public class CarSharingClass {

public string UserName = UserInfo.getUserId() ;
public Reservation__c res{get; set;}    
public user currentuser{get;set;}

public CarSharingClass (ApexPages.StandardController stdController) {
res.Fahrer__c = UserName;
currentuser=[Select Id,phone from User where Id=:res.Fahrer__c limit 1];
system.debug('currentuser:'+currentuser);        
res.Contact_Number__c = currentuser.phone ;      

}

public void LoadingUserDetails(){

currentuser=[Select Id,phone from User where Id=:res.Fahrer__c limit 1];
system.debug('changeduser:'+currentuser);
res.Contact_Number__c = currentuser.phone ;

}

}





 
Best Answer chosen by Shravya Rama 9
Shravya Rama 9Shravya Rama 9
I got to know that action support doesnt work well with look up fields. I found a work around which involves to create a button and call the same method to retrieve values.

All Answers

Adarsh.SharmaAdarsh.Sharma
Hi Shravya Rama,

you try this:

VF PAGE
<apex:inputField label="Fahrer" value="{!res.Fahrer__c}" >
<apex:actionSupport action="{!LoadingUserDetails}" rerender="out" />
</apex:inputField>
<apex:inputField label="Contact Nummer" value="{!res.Contact_Number__c}" rendered="true" id="out" />


Apex Class:
 
public class CarSharingClass {
//public string UserName = UserInfo.getUserId() ;
public Reservation__c res{get; set;}
public user currentuser{get;set;}
public CarSharingClass (ApexPages.StandardController stdController) {
res = new Reservation__c();
res.Fahrer__c = UserInfo.getUserId() ;
for(User oUser:[Select Id,Phone from User where Id=:res.Fahrer__c limit 1]){
     currentuser=oUser;
}
system.debug('currentuser:'+currentuser);

if(currentuser!=null){
  res.Contact_Number__c = currentuser.Phone ;
}


}
public void LoadingUserDetails(){
for(User oUser:[Select Id,Phone from User where Id=:res.Fahrer__c limit 1]){
     currentuser=oUser;
}
system.debug('changeduser:'+currentuser);
if(currentuser!=null){
  res.Contact_Number__c = currentuser.Phone ;
}
}
}

If this helps you please mark as best answer.
if your problem is not solved,then give your complete vf page.
Thanks



 
Shravya Rama 9Shravya Rama 9
Hello Adarsh Sharma,
The problem is still the same. system.debug('changeduser:'+currentuser); is not visible in the debug and it clearly means it's not calling the method LoadingUserDetails() from action support.  I have even tried action function and is still the same.
Shravya Rama 9Shravya Rama 9
I got to know that action support doesnt work well with look up fields. I found a work around which involves to create a button and call the same method to retrieve values.
This was selected as the best answer