0

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
2
  • So Interested__c is the name of the field on your Contact object?
    – Mark Pond
    Apr 15, 2016 at 23:44
  • yes its the field on contact Apr 15, 2016 at 23:50

4 Answers 4

3
select Id, Name, Interested__r.Name from Contact
0

Try this

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

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.

0

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.

You must log in to answer this question.

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