You need to sign in to do that
Don't have an account?
Child to Parent Relationship Query on a VF "New" page
I am trying to use a child-to-parent relationship to obain a Name value from the parent object on a "new" VisualForce page.
The child object is Data_Transaction__c and the parent object is Data_Activity__c.
The field Data_Activity__c is selected by a user and triggers a rerendering of the page. I then need to use the value of Data_Transaction__c.Data_Activity__r.Name as criteria for rendering the portion of the page appropriate for the selected Data Activity. Problem is Data_Transaction__c.Data_Activity__r.Name is null because the record is not actually saved yet. If I try to use just Data_Transaction__c.Data_Activity__c, it evaluates to the 18 character Id of the selected Data_Activity__c object.
Any suggestions on an alternative approach? Code sample below.
<apex:page standardController="Data_Transaction__c" sidebar="false" id="thePage">
<apex:sectionHeader title="Data Transaction Edit"subtitle="New Data Transaction"/>
<apex:form id="theForm">
<apex:pageBlock title="Data Transaction Edit" id="thePageBlock"mode="edit">
<apex:pageMessages rendered="false"/>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:actionRegion >
<apex:pageBlockSection title="Data Transaction Information"columns="1">
<apex:outputField value="{!Data_Transaction__c.Production_Number__c}"/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Activity Type"/>
<apex:outputPanel >
<apex:inputField value="{!Data_Transaction__c.Data_Activity__c}">
<apex:actionSupport event="onchange"
rerender="thePanel"
status="status"/>
</apex:inputField>
<apex:actionStatus startText=" Updating..."
id="status"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:outputPanel id="thePanel">
<apex:pageBlockSection title="Mortgage Details" columns="1" rendered="{!Data_Transaction__c.Data_Activity__r.Name == 'Mortgage'}">
<apex:inputField value="{!Data_Transaction__c.AS400__c}" rendered="{!Data_Transaction__c.Transaction_Type__c == 'Completed Work'}"/>
<apex:inputField value="{!Data_Transaction__c.HDES__c}" rendered="{!Data_Transaction__c.Transaction_Type__c == 'Completed Work'}"/>
<apex:inputField value="{!Data_Transaction__c.Not_Processed__c}" rendered="{!Data_Transaction__c.Transaction_Type__c == 'Completed Work'}" label="Canceled"/>
<apex:inputField value="{!Data_Transaction__c.Items__c}" required="true"/>
<apex:inputField value="{!Data_Transaction__c.Hours__c}" required="{!Data_Transaction__c.Transaction_Type__c == 'Completed Work'}" rendered="{!Data_Transaction__c.Transaction_Type__c == 'Completed Work'}"/>
</apex:pageBlockSection>
use extensions class... set a boolean value based on the Activity in the action method and use this boolean value to render the panel.