I have a custom object Called 'Interest_Level__c'. From contact I have a lookup to Interest_level__c object with relationship name 'Contacts' and Field 'Interested__c'. Now I'm trying to get the 'Name' of Interest_Level__c record.

Here is my query:

select Id, Name, Contacts__r.Name from Contact
  • So Interested__c is the name of the field on your Contact object?
    – Mark Pond
    Apr 15 '16 at 23:44
  • yes its the field on contact Apr 15 '16 at 23:50
select Id, Name, Interested__r.Name from Contact

Try this

    SELECT Id, Name, (Select Name from Contacts__r) FROM Interest_Level__c

when you want to use related lookup field (Interested__c) on any object (contact) then you have to use "Interested__c" field only it gives you only Id of related record (Interested__c).

When you want more information from lookup field like Name and other fields then we have to use lookup relationship object which is "Interested__r". This object will contains all information related to your lookup record.

It will provide name for related lookup record : select Id, Name, Interested__r.Name from Contact

Relationship type Name "Contacts" will be used only when you have to get all Interest_Level__c record related to contact.


This gives you the id of Interested record:

select Id, Name, Interested__c from Contact

This give you the Name:

select Id,Interested__r.Name from Contact

You need to use __r relationship when you are accessing the fields of a lookup field.

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.