+ Start a Discussion

Retrieving fields of parent object

Hai all,


I have a lookup from my custom object(say,Project) with Contact(standard object)  through the customfield contact__c.


Now,if I want to access the fields of Contact object through my custom object,how Can I do it?


I tried doing Project__c.Contact__r.Mobile,But it doesnt work.


Please help me figure it out.


I hope  {!xxxx.Contact_r.Mobile}  work.


do you retrieve "Project__c.Contact__r.Mobile" by SOQL in your apex class?


please show your apex code.





I have pasted the code below.



<apex:inputField value="{!Text_Message__c.name}"/ required="true"><br />
<apex:inputField value="{!Text_Message__c.Contact__c}"/><br />



<apex:inputField value="{!Text_Message__c.Contact__c}"/><br />


Above shown Is the field where I have a lookup with standard object(Contact__c)


<apex:inputField value="{!Text_Message__c.Contact__r.MobilePhone}"/><br />


For this field,I am unable to populate the field with the value.It only gives the label(say,Mobile) and not the value.


Thanks for the reply.


I hope this dont Work.

The value dont show, because you dont retrieve his.


For to retrieve the value, you have to use a call by SOQL, in your apex class. For Sample:

After saving the register, you call:


Private Final Text_Message__c TextMessage =  (Text_Message__c)controller.getRecord()


Private Text_Message__c showobject = new Text_Message__c();


Public Text_Message__c getShowMobile(){

   showobject = [select id, Contact__r.MobilePhone from Text_Message__c where id = TextMessage.id];

   return showobject;



public PageReference refreshPage(){

   showobject = getShowMobile();

   return null;



Finally, you call your method in your visualforce page:


<apex:inputField value="{!ShowMobile.Contact__r.Mobilephone}"/>