0

I am having a problem with a query. I am trying to extract the name of Assigned_To__c field (which is a look up field of Employee Rosters object).

The query I have used for this is

SELECT id, name, Assigned_To__r.Name 
FROM Work_Request__c 
WHERE Assigned_To__r.id =: id limit 201

The query is returning the value for the id and name fields correctly but for Assigned_To__r.Name, the id itself is getting returned not the employee name. Can someone tell me what i'm doing wrong?

Thanks

2

One of Two issues here:

  1. You are using the debug log to look at the value of the Query results i.e.

    Contact c = [Select Account.Name From Contact]
    system.debug(c);
    

To debug the actual name you will need to

system.debug(c.Account.Name);
  1. The name field is a text field and was not populated on inserting the record, in this case the name field will default to the ID of the record.
2
  • As you correctly guessed i am trying to check the value via debug log. ill try ur method and also will check if the field is populated, which i think it is. Dec 12 '14 at 14:31
  • And it worked like a charm. It was the problem with the debug. i am able to see the employee names now... Thanks Dec 12 '14 at 14:38
0

If you did not enter Name field for a record (ie) in this case it is Employee Rosters record/sObject, the Name field by default will have the ID of the record as the value!

-1

I think you can use Assigned_To__c directly - and maybe it's a typo, but I think you need a colon - not a semicolon:

SELECT id, name, Assigned_To__r.Name FROM Work_Request__c WHERE Assigned_To__c =:id limit 201

2
  • Assigned_To__c will return the id , since it's a lookup. Yes, the semicolon does appear to be a typo, else the query is fine.
    – Mahmood
    Dec 12 '14 at 14:27
  • The OP is specifically requesting that he/she be able to access the Name property of the record.
    – Eric
    Dec 12 '14 at 14:30
-1

Try.... SELECT id, name, Assigned_To__c.Name FROM Work_Request__c WHERE Assigned_To__c.id =;id limit 201

1
  • You cannot reference relationships via __c. In addition, your answer continues the OPs typo of the ; in the query
    – Eric
    Dec 12 '14 at 14:28

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.