You need to sign in to do that
Don't have an account?
Quan Dao 8
Populate Record's Name instead of Record's ID on Visualforce related list
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
VF:
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>
Change your code like below :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
Please note this VF page is on a custom object called My_Profile__c. The object in my Controller is the Game__c object which looks up to the My_Profile__c object as well as the Team__c object. I want to display the Team__c object's name related to the Game__c object on the VF page on the My_Profile__c object.
Same issue still..