function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
samonsamon 

need some help/sample code to retrieve parent object fields.

 

On VisualForce developer's guide page 54. It says: "

As with queries in the Force.com API, you can use merge field syntax to retrieve data from related records:

 

you can use of the owner of the account record that is associated with the contact.

 

You can traverse up to five levels of child-to-parent relationships. For example, if using the Contact standard controller, {!contact.Account.Owner.FirstName} (a three-level child-to-parent relationship) to return the name."

 

I tried and no data returned.

 

To be more specific, I have two lookup fields defined in my child object to lookup the campaign1 and campaign2 names and one lookup field just to the campaign object.

 

I would like to retrieve several campaign attributes for Campaign 1 and campaign 2 and display them on my VF page. How do I do it? Below is what I have now:

 

<apex:page standardController="child__c" >
<apex:form >


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

<apex:outputField value="{!child__c.campaign__r.NumberSent}" />


</apex:form>
</apex:page>

 

It does not display any values now. The problem is that I have two campaigns that I would like to retrieve the name and number sent values. the above code won't do it.

 

Thank you!

Pradeep_NavatarPradeep_Navatar

Find below a sample code :

 

<apex:page standardController="Contact">

            <apex:pageBlock title="Hello {!$User.FirstName}!">

            You are displaying contacts from the {!contact.name} .

            Click a contact's name to view his or her details.

            </apex:pageBlock>

            <apex:pageBlock >

            <apex:form >

                <apex:dataTable value="{!contact.CampaignMembers}" var="compaignmember" cellPadding="4" border="1">

                    <apex:column >

                                <apex:facet>Name</apex:facet>

                                    <apex:commandLink >

                                    {!compaignmember.Campaign.Name}

                                   <apex:param value="{!compaignmember.CampaignId}"/>

                                    </apex:commandLink>

                   </apex:column>

                </apex:dataTable>

 

            </apex:form>

            </apex:pageBlock>

            <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>

            </apex:page>

 

Hope this helps.

samonsamon

Thanks very much for the help.

 

But I have campaign 1 and campaign 2 two fields in the child object that related to the campaign object and I would like to obtain some attributes for both of them from the campaign(parent) object. How would I do about it? Thanks!