+ Start a Discussion
ESTEST 

Accessing related parent values when creating a child object from a related list

Hello, forum:

 

[Similar question to one I asked in a different thread...]

 

I've created a VF page for creating new child objects from a related list on a parent.  This page has a pageBlock at the top of the page where parent values are displayed.  The 'name' field of the parent displays just fine, but another custom field within the parent does not display.

 

I have this line in my VF page:

 

 

<apex:outputField id="projectName" value="{!Solicitor__c.SOL_Bidding_Opportunity__r.BO_Project_Name__c}"/>

 

But this field doesn't display.

 

My controller extension looks like this:

 

 

public class solicitorExtension { public solicitorExtension(ApexPages.StandardController controller) { Solicitor__c sol = (Solicitor__c)controller.getRecord(); //if you always create the child object through relatedList //parent should not be null if (sol.SOL_Bidding_Opportunity__c != null) { Bidding_Opportunity__c bo = [select BO_Bid_Due_Date_Time__c, BO_Project_Name__c from Bidding_Opportunity__c where id =: sol.SOL_Bidding_Opportunity__c limit 1]; sol.SOL_Bid_Due_Date_Time__c = bo.BO_Bid_Due_Date_Time__c; sol.SOL_Revision_Number__c = 'ORIG'; sol.SOL_Status__c = 'Prospective'; } } }

 

What am I doing wrong?

 

Thank you.

 

 

 

splitsplit
<apex:outputField id="projectName" value="{!bo.BO_Project_Name__c}"/>
bmabma

In your apex code, you are doing the query and assigning to the object "bo", but not to "Solicitor__c.SOL_Bidding_Opportunity__r".

 

If you add an extra assignment like below to the end of the if statement it should work.

 

 

sol.SOL_Bidding_Opportunity__r = bo;

 

 

 

elpaso750elpaso750

Hi Guys,

 

thanks for the post. I'm in a similar situation but having two parents, here's my controller extension :

 

 

public class mytest2runedit {



public mytest2runedit(ApexPages.standardController controller){

           Tests_to_run__c t2r = (Tests_to_run__c)controller.getRecord(); 

            Software_Testing__c st = [select id, version__c, Software_to_Be_Tested__c from Software_Testing__c where id =: t2r.Software_Testing__c limit 1];

            Testing_Item__c ftt = [select id, Software__c, Description__c from Testing_Item__c where id =: t2r.Testing_Item__c limit 1];

     }

}

 and the page :

 

<apex:page standardController="Tests_to_run__c" showHeader="true" extensions="mytest2runedit">

<apex:sectionHeader title="Testing the functionality" subtitle="{Tests_to_run__c.Testing_item__c[name]}"/> 

<apex:form id="Test2run" >

<apex:messages />

<apex:pageBlock > title="Testing the functionality" id="Test_Block" mode="edit">

<apex:messages />

<apex:pageBlockbuttons >

<apex:commandButton value="Save" action="{!save}"/>

<apex:commandButton value="Cancel" action="{!cancel}"/>

</apex:pageBlockbuttons>


<apex:pageBlockSection title="Complete the Test assigned to you" columns="2" collapsible="False">


<apex:outputField value="{!Tests_to_run__c.Name}"/>

<apex:outputField value="{!Tests_to_run__c.Owner}"/>

<apex:outputField value="{!st.Software_to_Be_Tested__c}"/> 

<apex:outputField value="{!st.Version__c}"/> 


<apex:outputField value="{!ftt.Software__c}"/>

<apex:outputField value="{!ftt.Description__c}"/>


<apex:inputField value="{!Tests_to_run__c.Compulsory__c}"/>

<apex:inputField value="{!Tests_to_run__c.Assigne_to_User__c}"/>

<apex:inputField value="{!Tests_to_run__c.Completed__c}"/> 

<apex:inputField value="{!Tests_to_run__c.Test_Comments__c}"/> 


</apex:pageBlockSection> 



</apex:pageBlock>

</apex:form>

</apex:page>

 

but the IDE returns the following error :   Save error: Unknown property 'Tests_to_run__cStandardController.st'

 

any suggestion ?

 

thanks in advance.

 

Alex