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
JPSeaburyJPSeabury 

Within a VF page, can I query a related record to the record currently in focus -- without calling Apex class or putting java script in my page?

Here's the code:
 
Code:
<apex:page standardController="Case">
  <!-- Alert Notification Wizard -->
  
  <apex:pageBlock title="Send Alert Wizard">
    This is an Internal (Cedar Point)  <b>Sev {!Case.Priority} ALERT</b>  Status Update for the <b>{!Case.Account.Name}</b> Account Team.
  </apex:PageBlock>
  <apex:PageBlock title="Current Case Information">
      <b>CUSTOMER: </b> {!Case.Account.Name}<br></br>
      <b>CASE: </b> {!Case.CaseNumber} <br></br>
      <b>SWITCH:</b> {!Case.Switch__c} <br></br>
      <b>CATEGORY:</b> {!Case.Category__c} <br></br>
      <b>OPENED: </b> {!Case.CreatedDate} <p/>
      <b>SYNOPSIS</b>: {!Case.Subject}<br></br>
  </apex:pageBlock>
</apex>

 
Here's what it looks like when it runs (from a sample Case object):
 
 
Switch__c is a custom field (Lookup relationship to a custom object called Switch), defined within my Case object.  Rather than displaying the 18-byte ID of the Switch record, I'd like to display the Switch name. 
 
That was pretty easy to do with the related Account record -- I could use merge field syntax to traverse up the parent child relationship (Case.Account.Name) ... but attempting the same syntax with the Switch (Case.Switch__c.Name) gives a syntax error:
 
Error: The class 'java.lang.String' does not have the property 'Name'.
 
Is there an easy way to reference this related records Name, without going adding a java query or referencing a function call in an Apex class?
 
 


Message Edited by JPSeabury on 07-28-2008 08:12 PM

Message Edited by JPSeabury on 07-28-2008 08:14 PM
Sam.arjSam.arj
I believe the type of relationship between Cases and Account is mater-detail not lookup and SF brings the master-detail relationship.

My suggestion is to extend your standard controller and added method that retrieves the values you are looking for to present on the page.


jwetzlerjwetzler
No, all you need to do is get the name off of the relationship.
{!Case.Switch__r.name}

by the way, outputField will automatically show you the name on Switch__c, and provide a link to that particular switch record.

Gemini@WorkGemini@Work

Perfect, Jill -- that worked awesome.  I didn't know about the "_r" relationship designator of a custom object.  Need to bone up on that now.  Thanks!

Good tip on the outputField option, as well -- although in this case, I'd prefer to not provide a link to the related record.  Still, it's nice to know about it for other VF pages.