3

I am trying to display a text field ,'RESOURCE', from the master object (this text field is manually entered on the VF page associated to the master object). This needs to be displayed on another VF page associated to the child object. So, I have written a code like this on the VF page(related to child object):

<apex:pageBlockSection id="DetailsSection" columns="1">
   <apex:outputField id="Resource" value="{!Child_Object__c.Master_Object__r.Resource__c}"/>
</apex:pageBlockSection>

But, when I open the VF page, the value doesn't appear however once I save the page after entering the rest of the details and reopen it the value appears.

3
  • so - this occurs on a 'New' Child_Object__c page?. Are you using the standardController for Child_Object__c or an extension/custom controller?
    – cropredy
    Jul 10, 2014 at 18:09
  • Yes, it happens on the New child_object_page. I am using an extension. I have a button on the master VF page from where I redirect to the child VF page and I am also displaying the name of the master record on the same child VF page like this and it works but it doesn't work for the text field. <apex:pageBlockSection id="DetailsSection" columns="1"><apex:outputField id="MasterName" value="{!Child_Object__c.Master_Object__r}"/></apex:pageBlockSection> Jul 10, 2014 at 18:19
  • can you paste the URL that forms when you click the master button ? I got an idea of what you are trying to do from here :P developer.salesforce.com/forums/?id=906F0000000AbO0IAK
    – Rao
    Jul 10, 2014 at 18:41

1 Answer 1

3

I think you have to query for the field of the master object that you want to show. Put this in the constructor of your controller:

//given that the parameter that's passed to the constructor of the controller
//is called stdController.
Child_Object__c record = (Child_Object__c)stdController.getRecord();
List<Master_Object__c> l = [SELECT Id, Resource__c
                              FROM Master_Object__c 
                              WHERE Id = :record.Master_Object__c];
if(l.size() > 0){
    record.Master_Object__r = l[0];
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .