1

These fields contain a person name in the usual format, but SOQL returns Id of the record as strings. Can the SOQL query results display this as the actual name? Thanks!!!

3
  • 1
    Can you include your soql query ? You've queried the relation which is the ID of the corresponding record. To query fields you'll have to use the relation to transcend into the parent/child fields. Commented Mar 13, 2014 at 10:59
  • 1
    In addition to the @Samuel De Rycke's reply I have noticed that if you are not populating the Name field of an object when inserting it by default it set the Id value of the record for the Name. Then when you are retrieving the data back, Name field will be having Id value.
    – highfive
    Commented Mar 13, 2014 at 11:04
  • Thanks. If you add as an answer I will accept it. I was using K__Resource__c and I needed to use K__Resource__r.Name
    – finisterre
    Commented Mar 13, 2014 at 11:49

1 Answer 1

7

This field have to be lookup. Lookup and Master-Detail are specific kind of field. From user perspective they are displayed as a name of parent object. But from code prespective those are Ids of parents objects.

If you want access name of parent object by SOQL you have to reference Name field on Parent object.

for custom object it will look like

SELECT ParentObjectLookup__r.Name FROM ChildObject.

'__r' construction allows you access parent object

In case of standard object you have to use same logic but construcyion is diffrent. For example thats how get Account Name from opportunity

SELECT Acccount.Name FROM Opportunity

Please read some more about SOQL to better understand relations in Salesforce .

You must log in to answer this question.

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