0

I am using SOQL to get team names from salesforce for each current project. It all returns, however the name is returned in ID format rather than the string name. This is confusing to me because when I examine the field in salesforce, the value IS a string. I have been unsuccessful at figuring out how to convert the ID in the string value for display purposes. Here is my SOQL statement:

Select Name, TeamName__c from Project__c where isCurrent__c = true

Like I said, when I examine the actual field in salesforce, the name of the team is a real value. I can't figure out why it is displaying in my query as an ID. There must be some simple solution about how to force the display to imitate that of its value as it appears in salesforce...I sure would appreciate any suggestions. Below is a picture of my current output...you will notice the long random ID. That is where there should be a string with the actual name of the team.

enter image description here

1
  • 1
    What type of field is TeamName__c? Do you have Salesforce Shield or some level of encryption turned on for your field? If you do a System.debug in your code, do you see the text as you expect?
    – Nick C
    Commented Aug 2, 2021 at 23:27

2 Answers 2

4

Lookup fields automatically look up the related record in the UI. To do so in your code, you need to follow the reference:

Select Name, TeamName__r.Name from Project__c where isCurrent__c = true

Where __r means "this is a custom relationship", and the Path__r.Field means you want a parent's field. You can replace Name with any other standard or custom field you may have, such as TeamName__r.TeamLeader__c or TeamName__r.CreatedById, or even TeamName__r.Owner.Name (you can have up to five such relationships chained together).

2

You are getting the ID of a team instead of a name because I think it is a lookup field on project__c. To fetch the name of the lookup field use __r.fieldname

Select Name, TeamName__r.Name from Project__c where isCurrent__c = true

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .