+ Start a Discussion

Trying to display a related object's name and ID does not work, is my syntax/approach correct?

This is Visual force related but I think the problem is in my code so I am asking it here.


I have a visualforce page displaying records from a custom object. It has one field settlement__c which is a lookup field and has a master-child relationship with another object called settlement.


I am displaying all records using a data table. The user has full access to both objects and all fields.

I am extracting data using a SOQL statement and have verified it returns the correct data in the query explorer.


These results are stored in a list which is used to populate the datatable columns,.

When I use Settlement__c , I can see a value in that column. But the same does not work when I use settlement__r.name or settlement__r.id which I need to obtain so that I can display a page with that record's information.


My code:


      <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Settlement" action="{!toggleSort}" rerender="results,debug,fundingReportResults,dataTable,errors,pageNumberPanel" styleClass="commandStyle">
                        <apex:param name="sortField" value="Settlement__r.id" assignTo="{!sortField}"/>
                <apex:outputLink onclick="window.open('/apex/InvoiceDetails?id={!mt.moneyTransactions.Settlement__r.id}');">    

 I am not getting anything, the id or name returned is null.


What am I missing here I was so sure it was security but apparently the user has full security to the object and has has field level security.

And why do I see data when I use Settlement__c instead of settlement__r.name/settlement__r.id?







In order to fetch Settlement ID only "Settlement__c" would be fine. That will work.

We need to use "__r" convention when we have to access the data from other table (except ID). In your case you just have to access the Id of your settlement record; and that gets stored in the relationship field anyhow. 




Hey Kukarni,


Thanks for your reply. Yes that is the way its working now. But what if I want to, lets say disply the name of the settlement as well?


And could you please tell me why using __r and accessing elements from it does not appear in my case?








In order to display the name of Settlement  "__r.Name" should work in your case. May be some issue with security in your case; but as you said you have checked the field level security it should work.


There is no official document which i have ever found about why "__r.Id" does not work. Just wrote a small script in my developer console and it works perfectly for me (atleast on console it is showing the value of "__r.Id" perfectly).



I thik the way you used it in your <apex:param /> tag is wrong. you have written value = "settlement__r.Id" i think you should use binding variable there and it will work fine


Can you please given an example of how the binding variable should be used?