• Quan Dao 8
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hi, 

I am new to Developing and have ran into a problem while playing around in my Dev Org. 

I am trying to create a VF page to display related records. However, I am getting the record Id instead of the Record's Name. Please help.

The issue comes from the fact that I am utilizing the Game__c's custom object Team__c  (which is retrieving the record id) . It doesn't allow me to retrieve the Game__c.Team__r.Name on the VF page as the controller is a different custom object.

Note: The Game__c object looks up to both the Team__C object and the My_Profile__c object.

Controller 
public with sharing class GamesPlayedController
{
    ApexPages.StandardController sc;
    public list <Game__c> Game {get; set;}
    public list <my_Profile__c> MyProfile {get; set;}
    
    
    public GamesPlayedController (ApexPages.StandardController sc)
    {
        this.sc = sc;
        
        Game = [SELECT Game_Outcome__C, Team__c, Player__c,  Team_Score__c, Opponent_Score__c,
                      Opponent_Team_Name__c, Player_s_Point__c,
                      Opponent_Name__c, CreatedDate, Team__r.Name, Player__r.Name
               FROM Game__c
               WHERE X2K__c IN ('2K19','2K18')
               ORDER BY CreatedDate
               DESC
               LIMIT 100];
       
       
         }     
    
    public ApexPages.PageReference SaveBoth()
    {
        insert Game;
        return sc.Save();   
        }  
            
     }

VF:
<apex:page standardController="My_Profile__c" lightningstylesheets="true" extensions="GamesPlayedController">

<Apex:form>
    <apex:pageBlock title="Games Played">
        <apex:pageBlockTable value="{!Game}" var="record">
            //<apex:repeat value="{!Game}" var="Field2">
            <apex:column>
                <apex:facet name="header"> 
                    Game Outcome
                </apex:facet>
                <apex:outputText value="{!record.Game_Outcome__C}"/>
            </apex:column>
            
            <apex:column>
                <apex:facet name="header">
                    Team
                </apex:facet>
                <apex:outputLink value="/{!record.Team__c}">                  
                        <apex:outputText value="{!record.Team__c}"/>                  
                </apex:outputLink>
            </apex:column>
            
            <apex:column>
                <apex:facet name="header">
                    Team Score
                </apex:facet>
                <apex:outputText value="{!record.Team_Score__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Opponent Score
                </apex:facet>
                <apex:outputText value="{!record.Opponent_Score__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Opponent Team Name
                </apex:facet>
                <apex:outputText value="{!record.Opponent_Team_Name__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Player
                </apex:facet>
                <apex:outputLink value="/{!record.Player__c}">             
                        <apex:outputText value="{!record.Player__c}"/>
                </apex:outputLink>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Player's Point
                </apex:facet>
                <apex:outputText value="{!record.Player_s_Point__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Opponent Name
                </apex:facet>
                <apex:outputText value="{!record.Opponent_Name__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Created Date
                </apex:facet>
                <apex:outputText value="{!record.CreatedDate}"/>
            </apex:column>
          // </apex:repeat>

        </apex:pageBlockTable>
    </apex:pageBlock>
</Apex:form>

</apex:page>

User-added image
Hi, 

I am new to Developing and have ran into a problem while playing around in my Dev Org. 

I am trying to create a VF page to display related records. However, I am getting the record Id instead of the Record's Name. Please help.

The issue comes from the fact that I am utilizing the Game__c's custom object Team__c  (which is retrieving the record id) . It doesn't allow me to retrieve the Game__c.Team__r.Name on the VF page as the controller is a different custom object.

Note: The Game__c object looks up to both the Team__C object and the My_Profile__c object.

Controller 
public with sharing class GamesPlayedController
{
    ApexPages.StandardController sc;
    public list <Game__c> Game {get; set;}
    public list <my_Profile__c> MyProfile {get; set;}
    
    
    public GamesPlayedController (ApexPages.StandardController sc)
    {
        this.sc = sc;
        
        Game = [SELECT Game_Outcome__C, Team__c, Player__c,  Team_Score__c, Opponent_Score__c,
                      Opponent_Team_Name__c, Player_s_Point__c,
                      Opponent_Name__c, CreatedDate, Team__r.Name, Player__r.Name
               FROM Game__c
               WHERE X2K__c IN ('2K19','2K18')
               ORDER BY CreatedDate
               DESC
               LIMIT 100];
       
       
         }     
    
    public ApexPages.PageReference SaveBoth()
    {
        insert Game;
        return sc.Save();   
        }  
            
     }

VF:
<apex:page standardController="My_Profile__c" lightningstylesheets="true" extensions="GamesPlayedController">

<Apex:form>
    <apex:pageBlock title="Games Played">
        <apex:pageBlockTable value="{!Game}" var="record">
            //<apex:repeat value="{!Game}" var="Field2">
            <apex:column>
                <apex:facet name="header"> 
                    Game Outcome
                </apex:facet>
                <apex:outputText value="{!record.Game_Outcome__C}"/>
            </apex:column>
            
            <apex:column>
                <apex:facet name="header">
                    Team
                </apex:facet>
                <apex:outputLink value="/{!record.Team__c}">                  
                        <apex:outputText value="{!record.Team__c}"/>                  
                </apex:outputLink>
            </apex:column>
            
            <apex:column>
                <apex:facet name="header">
                    Team Score
                </apex:facet>
                <apex:outputText value="{!record.Team_Score__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Opponent Score
                </apex:facet>
                <apex:outputText value="{!record.Opponent_Score__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Opponent Team Name
                </apex:facet>
                <apex:outputText value="{!record.Opponent_Team_Name__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Player
                </apex:facet>
                <apex:outputLink value="/{!record.Player__c}">             
                        <apex:outputText value="{!record.Player__c}"/>
                </apex:outputLink>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Player's Point
                </apex:facet>
                <apex:outputText value="{!record.Player_s_Point__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Opponent Name
                </apex:facet>
                <apex:outputText value="{!record.Opponent_Name__c}"/>
            </apex:column>
            
            <apex:column>
            <apex:facet name="header">
                    Created Date
                </apex:facet>
                <apex:outputText value="{!record.CreatedDate}"/>
            </apex:column>
          // </apex:repeat>

        </apex:pageBlockTable>
    </apex:pageBlock>
</Apex:form>

</apex:page>

User-added image