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!!!

  • 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. – Samuel De Rycke Mar 13 '14 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 Mar 13 '14 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 Mar 13 '14 at 11:49

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 .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.