You need to sign in to do that
Don't have an account?

Master-detail SOQL query
Hello,
I have a Master-detail relationship between Train-Ticket.
Using a SOQL query on Ticket I need to obtain a field value of the associated train.
This is the query I'm using :
public static void ticketInfo(ID ticketId){
Ticket__c ticket = [SELECT ID,Name,PAX_Type__c, Train__r.FPU_Train_Category__c
FROM Ticket__c
WHERE ID =: ticketID];
system.debug(ticket);
}
The issue is that instead of the desired field (FPU_Train_Category__c) it returns the Train's ID. I tried Train__r.Name and it still returned the ID.
Thanks a lot for explaining this to me!
Have a nice day
I have a Master-detail relationship between Train-Ticket.
Using a SOQL query on Ticket I need to obtain a field value of the associated train.
This is the query I'm using :
public static void ticketInfo(ID ticketId){
Ticket__c ticket = [SELECT ID,Name,PAX_Type__c, Train__r.FPU_Train_Category__c
FROM Ticket__c
WHERE ID =: ticketID];
system.debug(ticket);
}
The issue is that instead of the desired field (FPU_Train_Category__c) it returns the Train's ID. I tried Train__r.Name and it still returned the ID.
Thanks a lot for explaining this to me!
Have a nice day
Your query seems correct. However there may be chances that, you are debugging them in wrong way.
Kindly confirm you are using below debug to show train name:
Thanks,
Aman
All Answers
Could you please confirm FPU_Train_Category__c is lookup or text field which datatype?
If it is look up field then write below query.
SELECT ID,Name,PAX_Type__c, Train__r.FPU_Train_Category__r.name
FROM Ticket__c
WHERE ID =: ticketID
Thanks
Varaprasad
It's a text field so your query doesn't work.
Regards
Your query seems correct. However there may be chances that, you are debugging them in wrong way.
Kindly confirm you are using below debug to show train name:
Thanks,
Aman
Hi Aman,
That debugging actaully worked! Glad the query was right.
Any idea why my way of debugging doesn't work?
Thanks a lot
Is your issue resolved?
Please like the answer and mark it as best if this resolve your issue.
Thanks,
Áman